From bfaacc8a077daa48fb85e66a80e8f2904fce59a0 Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Mon, 14 Aug 2017 16:06:52 -0400 Subject: Refactor asdcApi Refactor asdcApi to replace openecomp references with onap Change-Id: Ic0d61ca75219a57331ba61908fba942a1c0dce7b Issue-ID: CCSDK-25 Signed-off-by: Dan Timoney --- asdcApi/features/src/main/resources/features.xml | 8 +- asdcApi/installer/pom.xml | 2 +- asdcApi/model/src/main/yang/ASDC-API.yang | 4 +- asdcApi/model/src/main/yang/asdc-api-common.yang | 4 +- .../model/src/main/yang/asdc-license-model.yang | 4 +- .../sli/northbound/asdcapi/AsdcApiProvider.java | 415 +++++++++++++++++++++ .../sli/northbound/asdcapi/AsdcApiSliClient.java | 111 ++++++ .../ccsdk/sli/northbound/asdcapi/AsdcApiUtil.java | 48 +++ .../impl/rev140523/AsdcApiProviderModule.java | 43 +++ .../rev140523/AsdcApiProviderModuleFactory.java | 34 ++ .../impl/rev140523/AsdcApiProviderModule.java | 57 --- .../rev140523/AsdcApiProviderModuleFactory.java | 34 -- .../openecomp/sdnc/asdcapi/AsdcApiProvider.java | 415 --------------------- .../openecomp/sdnc/asdcapi/AsdcApiSliClient.java | 111 ------ .../org/openecomp/sdnc/asdcapi/AsdcApiUtil.java | 48 --- .../main/resources/initial/asdcApi-provider.xml | 6 +- .../src/main/yang/asdcApi-provider-impl.yang | 2 +- 17 files changed, 664 insertions(+), 682 deletions(-) create mode 100644 asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java create mode 100644 asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiSliClient.java create mode 100644 asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiUtil.java create mode 100644 asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModule.java create mode 100644 asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModuleFactory.java delete mode 100644 asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/sdnc/asdcapi/provider/impl/rev140523/AsdcApiProviderModule.java delete mode 100644 asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/sdnc/asdcapi/provider/impl/rev140523/AsdcApiProviderModuleFactory.java delete mode 100644 asdcApi/provider/src/main/java/org/openecomp/sdnc/asdcapi/AsdcApiProvider.java delete mode 100644 asdcApi/provider/src/main/java/org/openecomp/sdnc/asdcapi/AsdcApiSliClient.java delete mode 100644 asdcApi/provider/src/main/java/org/openecomp/sdnc/asdcapi/AsdcApiUtil.java (limited to 'asdcApi') diff --git a/asdcApi/features/src/main/resources/features.xml b/asdcApi/features/src/main/resources/features.xml index e72e0f653..f9aa81a66 100644 --- a/asdcApi/features/src/main/resources/features.xml +++ b/asdcApi/features/src/main/resources/features.xml @@ -9,9 +9,7 @@ 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. @@ -31,11 +29,11 @@ odl-mdsal-broker - mvn:org.openecomp.sdnc.northbound/asdcApi-model/${project.version} - mvn:org.openecomp.sdnc.northbound/asdcApi-provider/${project.version} + mvn:org.onap.ccsdk.sli.northbound/asdcApi-model/${project.version} + mvn:org.onap.ccsdk.sli.northbound/asdcApi-provider/${project.version} sdnc-sli - mvn:org.openecomp.sdnc.northbound/asdcApi-provider/${project.version}/xml/config + mvn:org.onap.ccsdk.sli.northbound/asdcApi-provider/${project.version}/xml/config diff --git a/asdcApi/installer/pom.xml b/asdcApi/installer/pom.xml index 94008aaaf..b4f32934a 100755 --- a/asdcApi/installer/pom.xml +++ b/asdcApi/installer/pom.xml @@ -100,7 +100,7 @@ true false false - org.openecomp.sdnc + org.onap.ccsdk.sli.northbound sli-common,sli-provider,dblib-provider provided diff --git a/asdcApi/model/src/main/yang/ASDC-API.yang b/asdcApi/model/src/main/yang/ASDC-API.yang index 401ec7da9..00ef4522a 100755 --- a/asdcApi/model/src/main/yang/ASDC-API.yang +++ b/asdcApi/model/src/main/yang/ASDC-API.yang @@ -2,7 +2,7 @@ module ASDC-API { yang-version "1"; - namespace "org:openecomp:sdnc"; + namespace "org:onap:ccsdk"; prefix asdc-api; @@ -17,7 +17,7 @@ module ASDC-API { } organization - "OpenECOMP"; + "ONAP"; contact "Dan Timoney"; diff --git a/asdcApi/model/src/main/yang/asdc-api-common.yang b/asdcApi/model/src/main/yang/asdc-api-common.yang index 126368d4f..1531b7b30 100755 --- a/asdcApi/model/src/main/yang/asdc-api-common.yang +++ b/asdcApi/model/src/main/yang/asdc-api-common.yang @@ -3,12 +3,12 @@ module asdc-api-common { yang-version "1"; // Use same namespace defined for file upload in 15.12 - namespace "org:openecomp:sdnc:asdcapi:common"; + namespace "org:onap:ccsdk:sli:northbound:asdcapi:common"; prefix asdcapi; organization - "OpenECOMP"; + "ONAP"; contact "Dan Timoney"; diff --git a/asdcApi/model/src/main/yang/asdc-license-model.yang b/asdcApi/model/src/main/yang/asdc-license-model.yang index 37ae869bd..33f383569 100755 --- a/asdcApi/model/src/main/yang/asdc-license-model.yang +++ b/asdcApi/model/src/main/yang/asdc-license-model.yang @@ -1,8 +1,8 @@ module asdc-license-model { - namespace "http://xmlns.openecomp.org/asdc/license-model/1.0"; + namespace "http://xmlns.onap.org/asdc/license-model/1.0"; prefix le; - organization "openecomp"; + organization "onap"; contact "asdc"; description "schema for both vendor license and VF license models"; revision 2016-04-27 { diff --git a/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java new file mode 100644 index 000000000..c6e1921b7 --- /dev/null +++ b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java @@ -0,0 +1,415 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.northbound.asdcapi; + +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.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +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.http.xmlns.onap.org.asdc.license.model._1._0.rev160427.vf.license.model.grouping.VfLicenseModel; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.ASDCAPIService; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.Artifacts; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.ArtifactsBuilder; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.VfLicenseModelUpdateInput; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.VfLicenseModelUpdateInputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.VfLicenseModelUpdateOutput; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.VfLicenseModelUpdateOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.VfLicenseModelVersions; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.VfLicenseModelVersionsBuilder; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.artifacts.Artifact; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.artifacts.ArtifactBuilder; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.artifacts.ArtifactKey; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.vf.license.model.versions.VfLicenseModelVersion; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.vf.license.model.versions.VfLicenseModelVersionBuilder; +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; + +/** + * 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. + * + * To use this, copy and paste (overwrite) the following method into the TestApplicationProviderModule + * class which is auto generated under src/main/java in this project + * (created only once during first compilation): + * + *
+
+    @Override
+    public java.lang.AutoCloseable createInstance() {
+
+         final asdcApiProvider provider = new asdcApiProvider();
+         provider.setDataBroker( getDataBrokerDependency() );
+         provider.setNotificationService( getNotificationServiceDependency() );
+         provider.setRpcRegistry( getRpcRegistryDependency() );
+         provider.initialize();
+         return new AutoCloseable() {
+
+            @Override
+            public void close() throws Exception {
+                //TODO: CLOSE ANY REGISTRATION OBJECTS CREATED USING ABOVE BROKER/NOTIFICATION
+                //SERVIE/RPC REGISTRY
+                provider.close();
+            }
+        };
+    }
+
+
+    
+ */ +public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { + + private static final String ACTIVE_VERSION = "active"; + + private final Logger log = LoggerFactory.getLogger( AsdcApiProvider.class ); + private final String appName = "asdcApi"; + + private final ExecutorService executor; + protected DataBroker dataBroker; + protected NotificationProviderService notificationService; + protected RpcProviderRegistry rpcRegistry; + + protected BindingAwareBroker.RpcRegistration rpcRegistration; + + public AsdcApiProvider(DataBroker dataBroker2, + NotificationProviderService notificationProviderService, + RpcProviderRegistry rpcProviderRegistry) { + this.log.info( "Creating provider for " + appName ); + executor = Executors.newFixedThreadPool(1); + dataBroker = dataBroker2; + notificationService = notificationProviderService; + rpcRegistry = rpcProviderRegistry; + initialize(); + } + + public void initialize(){ + log.info( "Initializing provider for " + appName ); + + + createContainers(); + + if (rpcRegistration == null) { + if (rpcRegistry != null) { + rpcRegistration = rpcRegistry.addRpcImplementation( + ASDCAPIService.class, this); + log.info("Initialization complete for " + appName); + } else { + log.warn("Error initializing " + appName + + " : rpcRegistry unset"); + } + } + } + + private void createContainers() { + + if (dataBroker != null) { + final WriteTransaction t = dataBroker.newReadWriteTransaction(); + + // Create the vf-model-license-versions and artifacts containers + t.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(VfLicenseModelVersions.class), + new VfLicenseModelVersionsBuilder().build()); + + t.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(Artifacts.class), new ArtifactsBuilder().build()); + + + try { + CheckedFuture checkedFuture = t.submit(); + checkedFuture.get(); + log.info("Create Containers succeeded!: "); + + } catch (InterruptedException | ExecutionException e) { + log.error("Create Containers Failed: " + e); + e.printStackTrace(); + } + } else { + log.warn("createContainers : cannot find dataBroker to create containers"); + } + } + protected void initializeChild() { + //Override if you have custom initialization intelligence + } + + @Override + public void close() throws Exception { + log.info( "Closing provider for " + appName ); + executor.shutdown(); + rpcRegistration.close(); + log.info( "Successfully closed provider for " + appName ); + } + + public void setDataBroker(DataBroker dataBroker) { + this.dataBroker = dataBroker; + if( log.isDebugEnabled() ){ + log.debug( "DataBroker set to " + (dataBroker==null?"null":"non-null") + "." ); + } + } + + public void setNotificationService( + NotificationProviderService notificationService) { + this.notificationService = notificationService; + if( log.isDebugEnabled() ){ + log.debug( "Notification Service set to " + (notificationService==null?"null":"non-null") + "." ); + } + } + + public void setRpcRegistry(RpcProviderRegistry rpcRegistry) { + this.rpcRegistry = rpcRegistry; + + rpcRegistration = rpcRegistry.addRpcImplementation(ASDCAPIService.class, this); + + if( log.isDebugEnabled() ){ + log.debug( "RpcRegistry set to " + (rpcRegistry==null?"null":"non-null") + "." ); + } + } + + + protected boolean artifactVersionExists(String aName, String aVersion) { + InstanceIdentifier artifactInstanceId = + InstanceIdentifier.builder(Artifacts.class) + .child(Artifact.class, new ArtifactKey(aName, aVersion)).toInstance(); + ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction(); + Optional data = null; + try { + data = (Optional) readTx.read(LogicalDatastoreType.CONFIGURATION, artifactInstanceId).get(); + } catch (InterruptedException | ExecutionException e) { + log.error("Caught Exception reading MD-SAL for ["+aName+","+ aVersion+"] " ,e); + return false; + + } + + if (data.isPresent()) { + return true; + } else { + return false; + } + } + + protected void addArtifactVersion(String aName, String aVersion) { + + + try { + ArtifactBuilder aBuilder = new ArtifactBuilder(); + + aBuilder.setArtifactName(aName); + aBuilder.setArtifactVersion(aVersion); + + Artifact artifact = aBuilder.build(); + + InstanceIdentifier.InstanceIdentifierBuilder aIdBuilder = InstanceIdentifier + . builder(Artifacts.class) + .child(Artifact.class, artifact.getKey()); + + InstanceIdentifier path = aIdBuilder + .toInstance(); + + WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); + + tx.merge(LogicalDatastoreType.CONFIGURATION, path, + artifact); + tx.submit().checkedGet(); + } catch (Exception e) { + log.error("Caught exception trying to add artifact entry", e); + } + + } + + + private void applyVfLicenseModelUpdate(VfLicenseModelUpdateInput input) { + + String aName = input.getArtifactName(); + String aVersion = input.getArtifactVersion(); + VfLicenseModel vfLicenseModel = input.getVfLicenseModel(); + + + // Add new version (version = artifact-version) + try { + + VfLicenseModelVersionBuilder vBuilder = new VfLicenseModelVersionBuilder(); + vBuilder.setArtifactName(aName); + vBuilder.setArtifactVersion(aVersion); + vBuilder.setVfLicenseModel(vfLicenseModel); + + VfLicenseModelVersion version = vBuilder.build(); + + InstanceIdentifier.InstanceIdentifierBuilder versionIdBuilder = InstanceIdentifier + . builder(VfLicenseModelVersions.class) + .child(VfLicenseModelVersion.class, version.getKey()); + + InstanceIdentifier path = versionIdBuilder + .toInstance(); + + WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); + tx.merge(LogicalDatastoreType.CONFIGURATION, path, + version); + tx.submit().checkedGet(); + } catch (Exception e) { + log.error( + "Caught exception trying to save entry to MD-SAL", + e); + } + + + // Add "active" version (version = "active") + try { + + VfLicenseModelVersionBuilder vBuilder = new VfLicenseModelVersionBuilder(); + vBuilder.setArtifactName(aName); + vBuilder.setArtifactVersion(ACTIVE_VERSION); + vBuilder.setVfLicenseModel(vfLicenseModel); + + VfLicenseModelVersion version = vBuilder.build(); + InstanceIdentifier.InstanceIdentifierBuilder versionIdBuilder = InstanceIdentifier + . builder(VfLicenseModelVersions.class) + .child(VfLicenseModelVersion.class, version.getKey()); + + InstanceIdentifier path = versionIdBuilder + .toInstance(); + + WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); + + tx.merge(LogicalDatastoreType.CONFIGURATION, path, + version); + tx.submit().checkedGet(); + } catch (Exception e) { + log.error( + "Caught exception trying to save entry to MD-SAL", + e); + } + +} + +@Override +public Future> vfLicenseModelUpdate(VfLicenseModelUpdateInput input) { + final String SVC_OPERATION = "vf-license-model-update"; + + Properties parms = new Properties(); + + log.info( SVC_OPERATION +" called." ); + + if(input == null ) { + log.debug("exiting " +SVC_OPERATION+ " because of invalid input"); + return null; + } + + VfLicenseModelUpdateInputBuilder inputBuilder = new VfLicenseModelUpdateInputBuilder(input); + input = inputBuilder.build(); + + String errorMessage = "Success"; + String errorCode = "200"; + + // If this artifact already exists, reject this update + if (artifactVersionExists(input.getArtifactName(), input.getArtifactVersion())) { + errorCode = "409"; + errorMessage = "Artifact version already exists"; + } else { + // Translate input object into SLI-consumable properties + log.info("Adding INPUT data for "+SVC_OPERATION+" input: " + input); + AsdcApiUtil.toProperties(parms, input); + + + // Call directed graph + + Properties respProps = null; + + + AsdcApiSliClient sliClient = new AsdcApiSliClient(); + try + { + if (sliClient.hasGraph("ASDC-API", SVC_OPERATION , null, "sync")) + { + + try + { + respProps = sliClient.execute("ASDC-API", SVC_OPERATION, null, "sync", parms); + } + catch (Exception e) + { + log.error("Caught exception executing service logic for "+ SVC_OPERATION, e); + } + } else { + errorMessage = "No service logic active for ASDC-API: '" + SVC_OPERATION + "'"; + errorCode = "503"; + } + } + catch (Exception e) + { + errorCode = "500"; + errorMessage = e.getMessage(); + log.error("Caught exception looking for service logic", e); + } + + + if (respProps != null) + { + errorCode = respProps.getProperty("error-code"); + errorMessage = respProps.getProperty("error-message", ""); + } + } + + + if ("200".equals(errorCode)) { + log.info("ASDC update succeeded"); + + // Update config tree + applyVfLicenseModelUpdate(input); + addArtifactVersion(input.getArtifactName(), input.getArtifactVersion()); + + } else { + log.info("ASDC update failed ("+errorCode+" : "+errorMessage); + } + + // Send response + VfLicenseModelUpdateOutputBuilder respBuilder = new VfLicenseModelUpdateOutputBuilder(); + respBuilder.setAsdcApiResponseCode(errorCode); + if (errorMessage != null && errorMessage.length() > 0) { + respBuilder.setAsdcApiResponseText(errorMessage); + } + + RpcResult rpcResult; + + + rpcResult = RpcResultBuilder. status(true).withResult(respBuilder.build()).build(); + + + + return Futures.immediateFuture(rpcResult); +} + + +} diff --git a/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiSliClient.java b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiSliClient.java new file mode 100644 index 000000000..0fa90ea7e --- /dev/null +++ b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiSliClient.java @@ -0,0 +1,111 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.northbound.asdcapi; + +import java.util.Properties; + +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.Logger; +import org.slf4j.LoggerFactory; + +public class AsdcApiSliClient { + + private static final Logger LOG = LoggerFactory + .getLogger(AsdcApiSliClient.class); + + private SvcLogicService svcLogic = null; + + public AsdcApiSliClient() + { + BundleContext bctx = FrameworkUtil.getBundle(SvcLogicService.class).getBundleContext(); + + // 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 + { + return(svcLogic.hasGraph(module, rpc, version, mode)); + } + + + public Properties execute(String module, String rpc, String version, String mode, Properties parms) + 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 = svcLogic.execute(module, rpc, version, mode, parms); + + 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/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiUtil.java b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiUtil.java new file mode 100644 index 000000000..6498f13b5 --- /dev/null +++ b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiUtil.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.northbound.asdcapi; + +import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.ArtifactsBuilder; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.VfLicenseModelUpdateInput; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.VfLicenseModelUpdateInputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.VfLicenseModelVersionsBuilder; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.vf.license.model.versions.VfLicenseModelVersionBuilder; + +public class AsdcApiUtil extends MdsalHelper { + + static { + + // Input objects + + VfLicenseModelUpdateInput i13 = new VfLicenseModelUpdateInputBuilder().build(); + + + // Other builders + ArtifactsBuilder b1 = new ArtifactsBuilder(); + + VfLicenseModelVersionsBuilder b14a = new VfLicenseModelVersionsBuilder(); + VfLicenseModelVersionBuilder b26a = new VfLicenseModelVersionBuilder(); + + + } +} diff --git a/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModule.java b/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModule.java new file mode 100644 index 000000000..0a2272d35 --- /dev/null +++ b/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModule.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.asdcapi.provider.impl.rev140523; +public class AsdcApiProviderModule extends org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.asdcapi.provider.impl.rev140523.AbstractAsdcApiProviderModule { + public AsdcApiProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public AsdcApiProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.asdcapi.provider.impl.rev140523.AsdcApiProviderModule oldModule, java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() { + // add custom validation form module attributes here. + } + + @Override + public java.lang.AutoCloseable createInstance() { + // TODO:implement + throw new java.lang.UnsupportedOperationException(); + } + +} diff --git a/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModuleFactory.java b/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModuleFactory.java new file mode 100644 index 000000000..c2d15b890 --- /dev/null +++ b/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModuleFactory.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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========================================================= + */ + +/* +* Generated file +* +* Generated from: yang module name: asdcApi-provider-impl yang module local name: asdcApi-provider-impl +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Mon Aug 14 15:34:51 EDT 2017 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.asdcapi.provider.impl.rev140523; +public class AsdcApiProviderModuleFactory extends org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.asdcapi.provider.impl.rev140523.AbstractAsdcApiProviderModuleFactory { + +} diff --git a/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/sdnc/asdcapi/provider/impl/rev140523/AsdcApiProviderModule.java b/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/sdnc/asdcapi/provider/impl/rev140523/AsdcApiProviderModule.java deleted file mode 100644 index c9223a15c..000000000 --- a/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/sdnc/asdcapi/provider/impl/rev140523/AsdcApiProviderModule.java +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.opendaylight.yang.gen.v1.org.openecomp.sdnc.asdcapi.provider.impl.rev140523; - -import org.openecomp.sdnc.asdcapi.AsdcApiProvider; - -public class AsdcApiProviderModule extends org.opendaylight.yang.gen.v1.org.openecomp.sdnc.asdcapi.provider.impl.rev140523.AbstractAsdcApiProviderModule { - public AsdcApiProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { - super(identifier, dependencyResolver); - } - - public AsdcApiProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.org.openecomp.sdnc.asdcapi.provider.impl.rev140523.AsdcApiProviderModule oldModule, java.lang.AutoCloseable oldInstance) { - super(identifier, dependencyResolver, oldModule, oldInstance); - } - - @Override - public void customValidation() { - // add custom validation form module attributes here. - } - - @Override - public java.lang.AutoCloseable createInstance() { - - final AsdcApiProvider provider = new AsdcApiProvider(getDataBrokerDependency() - , getNotificationServiceDependency() - , getRpcRegistryDependency()); - - return new AutoCloseable() { - - @Override - public void close() throws Exception { - - provider.close(); - } - }; - } - -} diff --git a/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/sdnc/asdcapi/provider/impl/rev140523/AsdcApiProviderModuleFactory.java b/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/sdnc/asdcapi/provider/impl/rev140523/AsdcApiProviderModuleFactory.java deleted file mode 100644 index 6a1d8068e..000000000 --- a/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/sdnc/asdcapi/provider/impl/rev140523/AsdcApiProviderModuleFactory.java +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP 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========================================================= - */ - -/* -* Generated file -* -* Generated from: yang module name: asdcApi-provider-impl yang module local name: asdcApi-provider-impl -* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator -* Generated at: Wed Nov 02 03:46:08 EDT 2016 -* -* Do not modify this file unless it is present under src/main directory -*/ -package org.opendaylight.yang.gen.v1.org.openecomp.sdnc.asdcapi.provider.impl.rev140523; -public class AsdcApiProviderModuleFactory extends org.opendaylight.yang.gen.v1.org.openecomp.sdnc.asdcapi.provider.impl.rev140523.AbstractAsdcApiProviderModuleFactory { - -} diff --git a/asdcApi/provider/src/main/java/org/openecomp/sdnc/asdcapi/AsdcApiProvider.java b/asdcApi/provider/src/main/java/org/openecomp/sdnc/asdcapi/AsdcApiProvider.java deleted file mode 100644 index 28e59c8d7..000000000 --- a/asdcApi/provider/src/main/java/org/openecomp/sdnc/asdcapi/AsdcApiProvider.java +++ /dev/null @@ -1,415 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.asdcapi; - -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.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; -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.http.xmlns.openecomp.org.asdc.license.model._1._0.rev160427.vf.license.model.grouping.VfLicenseModel; -import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.rev170201.ASDCAPIService; -import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.rev170201.Artifacts; -import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.rev170201.ArtifactsBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.rev170201.VfLicenseModelUpdateInput; -import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.rev170201.VfLicenseModelUpdateInputBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.rev170201.VfLicenseModelUpdateOutput; -import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.rev170201.VfLicenseModelUpdateOutputBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.rev170201.VfLicenseModelVersions; -import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.rev170201.VfLicenseModelVersionsBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.rev170201.artifacts.Artifact; -import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.rev170201.artifacts.ArtifactBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.rev170201.artifacts.ArtifactKey; -import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.rev170201.vf.license.model.versions.VfLicenseModelVersion; -import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.rev170201.vf.license.model.versions.VfLicenseModelVersionBuilder; -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; - -/** - * 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. - * - * To use this, copy and paste (overwrite) the following method into the TestApplicationProviderModule - * class which is auto generated under src/main/java in this project - * (created only once during first compilation): - * - *
-
-    @Override
-    public java.lang.AutoCloseable createInstance() {
-
-         final asdcApiProvider provider = new asdcApiProvider();
-         provider.setDataBroker( getDataBrokerDependency() );
-         provider.setNotificationService( getNotificationServiceDependency() );
-         provider.setRpcRegistry( getRpcRegistryDependency() );
-         provider.initialize();
-         return new AutoCloseable() {
-
-            @Override
-            public void close() throws Exception {
-                //TODO: CLOSE ANY REGISTRATION OBJECTS CREATED USING ABOVE BROKER/NOTIFICATION
-                //SERVIE/RPC REGISTRY
-                provider.close();
-            }
-        };
-    }
-
-
-    
- */ -public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { - - private static final String ACTIVE_VERSION = "active"; - - private final Logger log = LoggerFactory.getLogger( AsdcApiProvider.class ); - private final String appName = "asdcApi"; - - private final ExecutorService executor; - protected DataBroker dataBroker; - protected NotificationProviderService notificationService; - protected RpcProviderRegistry rpcRegistry; - - protected BindingAwareBroker.RpcRegistration rpcRegistration; - - public AsdcApiProvider(DataBroker dataBroker2, - NotificationProviderService notificationProviderService, - RpcProviderRegistry rpcProviderRegistry) { - this.log.info( "Creating provider for " + appName ); - executor = Executors.newFixedThreadPool(1); - dataBroker = dataBroker2; - notificationService = notificationProviderService; - rpcRegistry = rpcProviderRegistry; - initialize(); - } - - public void initialize(){ - log.info( "Initializing provider for " + appName ); - - - createContainers(); - - if (rpcRegistration == null) { - if (rpcRegistry != null) { - rpcRegistration = rpcRegistry.addRpcImplementation( - ASDCAPIService.class, this); - log.info("Initialization complete for " + appName); - } else { - log.warn("Error initializing " + appName - + " : rpcRegistry unset"); - } - } - } - - private void createContainers() { - - if (dataBroker != null) { - final WriteTransaction t = dataBroker.newReadWriteTransaction(); - - // Create the vf-model-license-versions and artifacts containers - t.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(VfLicenseModelVersions.class), - new VfLicenseModelVersionsBuilder().build()); - - t.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(Artifacts.class), new ArtifactsBuilder().build()); - - - try { - CheckedFuture checkedFuture = t.submit(); - checkedFuture.get(); - log.info("Create Containers succeeded!: "); - - } catch (InterruptedException | ExecutionException e) { - log.error("Create Containers Failed: " + e); - e.printStackTrace(); - } - } else { - log.warn("createContainers : cannot find dataBroker to create containers"); - } - } - protected void initializeChild() { - //Override if you have custom initialization intelligence - } - - @Override - public void close() throws Exception { - log.info( "Closing provider for " + appName ); - executor.shutdown(); - rpcRegistration.close(); - log.info( "Successfully closed provider for " + appName ); - } - - public void setDataBroker(DataBroker dataBroker) { - this.dataBroker = dataBroker; - if( log.isDebugEnabled() ){ - log.debug( "DataBroker set to " + (dataBroker==null?"null":"non-null") + "." ); - } - } - - public void setNotificationService( - NotificationProviderService notificationService) { - this.notificationService = notificationService; - if( log.isDebugEnabled() ){ - log.debug( "Notification Service set to " + (notificationService==null?"null":"non-null") + "." ); - } - } - - public void setRpcRegistry(RpcProviderRegistry rpcRegistry) { - this.rpcRegistry = rpcRegistry; - - rpcRegistration = rpcRegistry.addRpcImplementation(ASDCAPIService.class, this); - - if( log.isDebugEnabled() ){ - log.debug( "RpcRegistry set to " + (rpcRegistry==null?"null":"non-null") + "." ); - } - } - - - protected boolean artifactVersionExists(String aName, String aVersion) { - InstanceIdentifier artifactInstanceId = - InstanceIdentifier.builder(Artifacts.class) - .child(Artifact.class, new ArtifactKey(aName, aVersion)).toInstance(); - ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction(); - Optional data = null; - try { - data = (Optional) readTx.read(LogicalDatastoreType.CONFIGURATION, artifactInstanceId).get(); - } catch (InterruptedException | ExecutionException e) { - log.error("Caught Exception reading MD-SAL for ["+aName+","+ aVersion+"] " ,e); - return false; - - } - - if (data.isPresent()) { - return true; - } else { - return false; - } - } - - protected void addArtifactVersion(String aName, String aVersion) { - - - try { - ArtifactBuilder aBuilder = new ArtifactBuilder(); - - aBuilder.setArtifactName(aName); - aBuilder.setArtifactVersion(aVersion); - - Artifact artifact = aBuilder.build(); - - InstanceIdentifier.InstanceIdentifierBuilder aIdBuilder = InstanceIdentifier - . builder(Artifacts.class) - .child(Artifact.class, artifact.getKey()); - - InstanceIdentifier path = aIdBuilder - .toInstance(); - - WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); - - tx.merge(LogicalDatastoreType.CONFIGURATION, path, - artifact); - tx.submit().checkedGet(); - } catch (Exception e) { - log.error("Caught exception trying to add artifact entry", e); - } - - } - - - private void applyVfLicenseModelUpdate(VfLicenseModelUpdateInput input) { - - String aName = input.getArtifactName(); - String aVersion = input.getArtifactVersion(); - VfLicenseModel vfLicenseModel = input.getVfLicenseModel(); - - - // Add new version (version = artifact-version) - try { - - VfLicenseModelVersionBuilder vBuilder = new VfLicenseModelVersionBuilder(); - vBuilder.setArtifactName(aName); - vBuilder.setArtifactVersion(aVersion); - vBuilder.setVfLicenseModel(vfLicenseModel); - - VfLicenseModelVersion version = vBuilder.build(); - - InstanceIdentifier.InstanceIdentifierBuilder versionIdBuilder = InstanceIdentifier - . builder(VfLicenseModelVersions.class) - .child(VfLicenseModelVersion.class, version.getKey()); - - InstanceIdentifier path = versionIdBuilder - .toInstance(); - - WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); - tx.merge(LogicalDatastoreType.CONFIGURATION, path, - version); - tx.submit().checkedGet(); - } catch (Exception e) { - log.error( - "Caught exception trying to save entry to MD-SAL", - e); - } - - - // Add "active" version (version = "active") - try { - - VfLicenseModelVersionBuilder vBuilder = new VfLicenseModelVersionBuilder(); - vBuilder.setArtifactName(aName); - vBuilder.setArtifactVersion(ACTIVE_VERSION); - vBuilder.setVfLicenseModel(vfLicenseModel); - - VfLicenseModelVersion version = vBuilder.build(); - InstanceIdentifier.InstanceIdentifierBuilder versionIdBuilder = InstanceIdentifier - . builder(VfLicenseModelVersions.class) - .child(VfLicenseModelVersion.class, version.getKey()); - - InstanceIdentifier path = versionIdBuilder - .toInstance(); - - WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); - - tx.merge(LogicalDatastoreType.CONFIGURATION, path, - version); - tx.submit().checkedGet(); - } catch (Exception e) { - log.error( - "Caught exception trying to save entry to MD-SAL", - e); - } - -} - -@Override -public Future> vfLicenseModelUpdate(VfLicenseModelUpdateInput input) { - final String SVC_OPERATION = "vf-license-model-update"; - - Properties parms = new Properties(); - - log.info( SVC_OPERATION +" called." ); - - if(input == null ) { - log.debug("exiting " +SVC_OPERATION+ " because of invalid input"); - return null; - } - - VfLicenseModelUpdateInputBuilder inputBuilder = new VfLicenseModelUpdateInputBuilder(input); - input = inputBuilder.build(); - - String errorMessage = "Success"; - String errorCode = "200"; - - // If this artifact already exists, reject this update - if (artifactVersionExists(input.getArtifactName(), input.getArtifactVersion())) { - errorCode = "409"; - errorMessage = "Artifact version already exists"; - } else { - // Translate input object into SLI-consumable properties - log.info("Adding INPUT data for "+SVC_OPERATION+" input: " + input); - AsdcApiUtil.toProperties(parms, input); - - - // Call directed graph - - Properties respProps = null; - - - AsdcApiSliClient sliClient = new AsdcApiSliClient(); - try - { - if (sliClient.hasGraph("ASDC-API", SVC_OPERATION , null, "sync")) - { - - try - { - respProps = sliClient.execute("ASDC-API", SVC_OPERATION, null, "sync", parms); - } - catch (Exception e) - { - log.error("Caught exception executing service logic for "+ SVC_OPERATION, e); - } - } else { - errorMessage = "No service logic active for ASDC-API: '" + SVC_OPERATION + "'"; - errorCode = "503"; - } - } - catch (Exception e) - { - errorCode = "500"; - errorMessage = e.getMessage(); - log.error("Caught exception looking for service logic", e); - } - - - if (respProps != null) - { - errorCode = respProps.getProperty("error-code"); - errorMessage = respProps.getProperty("error-message", ""); - } - } - - - if ("200".equals(errorCode)) { - log.info("ASDC update succeeded"); - - // Update config tree - applyVfLicenseModelUpdate(input); - addArtifactVersion(input.getArtifactName(), input.getArtifactVersion()); - - } else { - log.info("ASDC update failed ("+errorCode+" : "+errorMessage); - } - - // Send response - VfLicenseModelUpdateOutputBuilder respBuilder = new VfLicenseModelUpdateOutputBuilder(); - respBuilder.setAsdcApiResponseCode(errorCode); - if (errorMessage != null && errorMessage.length() > 0) { - respBuilder.setAsdcApiResponseText(errorMessage); - } - - RpcResult rpcResult; - - - rpcResult = RpcResultBuilder. status(true).withResult(respBuilder.build()).build(); - - - - return Futures.immediateFuture(rpcResult); -} - - -} diff --git a/asdcApi/provider/src/main/java/org/openecomp/sdnc/asdcapi/AsdcApiSliClient.java b/asdcApi/provider/src/main/java/org/openecomp/sdnc/asdcapi/AsdcApiSliClient.java deleted file mode 100644 index 2f3a783ba..000000000 --- a/asdcApi/provider/src/main/java/org/openecomp/sdnc/asdcapi/AsdcApiSliClient.java +++ /dev/null @@ -1,111 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.asdcapi; - -import java.util.Properties; - -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.Logger; -import org.slf4j.LoggerFactory; - -public class AsdcApiSliClient { - - private static final Logger LOG = LoggerFactory - .getLogger(AsdcApiSliClient.class); - - private SvcLogicService svcLogic = null; - - public AsdcApiSliClient() - { - BundleContext bctx = FrameworkUtil.getBundle(SvcLogicService.class).getBundleContext(); - - // 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 - { - return(svcLogic.hasGraph(module, rpc, version, mode)); - } - - - public Properties execute(String module, String rpc, String version, String mode, Properties parms) - 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 = svcLogic.execute(module, rpc, version, mode, parms); - - 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/asdcApi/provider/src/main/java/org/openecomp/sdnc/asdcapi/AsdcApiUtil.java b/asdcApi/provider/src/main/java/org/openecomp/sdnc/asdcapi/AsdcApiUtil.java deleted file mode 100644 index 240c939b4..000000000 --- a/asdcApi/provider/src/main/java/org/openecomp/sdnc/asdcapi/AsdcApiUtil.java +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.asdcapi; - -import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper; -import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.rev170201.ArtifactsBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.rev170201.VfLicenseModelUpdateInput; -import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.rev170201.VfLicenseModelUpdateInputBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.rev170201.VfLicenseModelVersionsBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.rev170201.vf.license.model.versions.VfLicenseModelVersionBuilder; - -public class AsdcApiUtil extends MdsalHelper { - - static { - - // Input objects - - VfLicenseModelUpdateInput i13 = new VfLicenseModelUpdateInputBuilder().build(); - - - // Other builders - ArtifactsBuilder b1 = new ArtifactsBuilder(); - - VfLicenseModelVersionsBuilder b14a = new VfLicenseModelVersionsBuilder(); - VfLicenseModelVersionBuilder b26a = new VfLicenseModelVersionBuilder(); - - - } -} diff --git a/asdcApi/provider/src/main/resources/initial/asdcApi-provider.xml b/asdcApi/provider/src/main/resources/initial/asdcApi-provider.xml index ab2da905f..53f5a11d0 100644 --- a/asdcApi/provider/src/main/resources/initial/asdcApi-provider.xml +++ b/asdcApi/provider/src/main/resources/initial/asdcApi-provider.xml @@ -9,9 +9,7 @@ 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. @@ -29,7 +27,7 @@ - + prefix:asdcApi-provider-impl asdcApi-provider-impl @@ -66,7 +64,7 @@ our service can be resolved. Capabilities for dependencies defined above are implied which is why we do not have define a required capability for the data broker, for example. --> - org:openecomp:sdnc:asdcapi:provider:impl?module=asdcApi-provider-impl&revision=2014-05-23 + org:onap:ccsdk:sli:northbound:asdcapi:provider:impl?module=asdcApi-provider-impl&revision=2014-05-23 diff --git a/asdcApi/provider/src/main/yang/asdcApi-provider-impl.yang b/asdcApi/provider/src/main/yang/asdcApi-provider-impl.yang index 94ee88368..7a1876cc1 100755 --- a/asdcApi/provider/src/main/yang/asdcApi-provider-impl.yang +++ b/asdcApi/provider/src/main/yang/asdcApi-provider-impl.yang @@ -1,7 +1,7 @@ module asdcApi-provider-impl { yang-version 1; - namespace "org:openecomp:sdnc:asdcapi:provider:impl"; + namespace "org:onap:ccsdk:sli:northbound:asdcapi:provider:impl"; prefix "asdcApi-provider-impl"; import config { prefix config; revision-date 2013-04-05; } -- cgit 1.2.3-korg