From 8881ebb497e9f35e5ea9d19923fd926db56e8f12 Mon Sep 17 00:00:00 2001 From: Ryan Goulding Date: Thu, 7 Sep 2017 12:10:08 -0400 Subject: Fix SDNC service registration This change converts AsdcApiProvider and AsdcApiSliClient to utilize Aries Blueprint for service instantiation instead of the ODL Config Subsystem. Change-Id: I5eaebe4c6e5b33fc8beb20b2cfe9acb6e8b6d808 Issue-Id: SDNC-54 Signed-off-by: Ryan Goulding --- .../sli/northbound/asdcapi/AsdcApiProvider.java | 93 ++++++++-------------- .../sli/northbound/asdcapi/AsdcApiSliClient.java | 29 ++----- .../impl/rev140523/AsdcApiProviderModule.java | 59 -------------- .../rev140523/AsdcApiProviderModuleFactory.java | 34 -------- .../main/resources/initial/asdcApi-provider.xml | 70 ---------------- .../org/opendaylight/blueprint/asdc-blueprint.xml | 32 ++++++++ .../src/main/yang/asdcApi-provider-impl.yang | 61 -------------- 7 files changed, 71 insertions(+), 307 deletions(-) delete mode 100644 asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModule.java delete 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/resources/initial/asdcApi-provider.xml create mode 100644 asdcApi/provider/src/main/resources/org/opendaylight/blueprint/asdc-blueprint.xml delete mode 100755 asdcApi/provider/src/main/yang/asdcApi-provider-impl.yang (limited to 'asdcApi/provider/src/main') 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 index bd5f74a4..13198d62 100644 --- 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 @@ -95,32 +95,36 @@ import com.google.common.util.concurrent.Futures; */ public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { + private static final Logger LOG = LoggerFactory.getLogger(AsdcApiProvider.class); + private static final String ACTIVE_VERSION = "active"; - private final Logger log = LoggerFactory.getLogger( AsdcApiProvider.class ); - private final String appName = "asdcApi"; + private static final String APPLICATION_NAME = "asdcApi"; private final ExecutorService executor; protected DataBroker dataBroker; protected NotificationProviderService notificationService; protected RpcProviderRegistry rpcRegistry; + private final AsdcApiSliClient asdcApiSliClient; protected BindingAwareBroker.RpcRegistration rpcRegistration; - public AsdcApiProvider(DataBroker dataBroker2, - NotificationProviderService notificationProviderService, - RpcProviderRegistry rpcProviderRegistry) { - this.log.info( "Creating provider for " + appName ); + public AsdcApiProvider(final DataBroker dataBroker, + final NotificationProviderService notificationProviderService, + final RpcProviderRegistry rpcProviderRegistry, + final AsdcApiSliClient asdcApiSliClient) { + + LOG.info("Creating provider for {}", APPLICATION_NAME); executor = Executors.newFixedThreadPool(1); - dataBroker = dataBroker2; + this.dataBroker = dataBroker; notificationService = notificationProviderService; rpcRegistry = rpcProviderRegistry; + this.asdcApiSliClient= asdcApiSliClient; initialize(); } public void initialize(){ - log.info( "Initializing provider for " + appName ); - + LOG.info("Initializing {} for {}", this.getClass().getName(), APPLICATION_NAME); createContainers(); @@ -128,10 +132,9 @@ public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { if (rpcRegistry != null) { rpcRegistration = rpcRegistry.addRpcImplementation( ASDCAPIService.class, this); - log.info("Initialization complete for " + appName); + LOG.info("Initialization complete for {}", APPLICATION_NAME); } else { - log.warn("Error initializing " + appName - + " : rpcRegistry unset"); + LOG.warn("Error initializing {} : rpcRegistry unset", APPLICATION_NAME); } } } @@ -151,14 +154,14 @@ public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { try { CheckedFuture checkedFuture = t.submit(); checkedFuture.get(); - log.info("Create Containers succeeded!: "); + LOG.info("Create Containers succeeded!: "); } catch (InterruptedException | ExecutionException e) { - log.error("Create Containers Failed: " + e); + LOG.error("Create Containers Failed: " + e); e.printStackTrace(); } } else { - log.warn("createContainers : cannot find dataBroker to create containers"); + LOG.warn("createContainers : cannot find dataBroker to create containers"); } } protected void initializeChild() { @@ -167,38 +170,12 @@ public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { @Override public void close() throws Exception { - log.info( "Closing provider for " + appName ); + LOG.info( "Closing provider for " + APPLICATION_NAME); 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") + "." ); - } + LOG.info( "Successfully closed provider for " + APPLICATION_NAME); } - protected boolean artifactVersionExists(String aName, String aVersion) { InstanceIdentifier artifactInstanceId = InstanceIdentifier.builder(Artifacts.class) @@ -208,7 +185,7 @@ public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { try { data = (Optional) readTx.read(LogicalDatastoreType.CONFIGURATION, artifactInstanceId).get(); } catch (InterruptedException | ExecutionException e) { - log.error("Caught Exception reading MD-SAL for ["+aName+","+ aVersion+"] " ,e); + LOG.error("Caught Exception reading MD-SAL for ["+aName+","+ aVersion+"] " ,e); return false; } @@ -244,7 +221,7 @@ public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { artifact); tx.submit().checkedGet(); } catch (Exception e) { - log.error("Caught exception trying to add artifact entry", e); + LOG.error("Caught exception trying to add artifact entry", e); } } @@ -279,7 +256,7 @@ public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { version); tx.submit().checkedGet(); } catch (Exception e) { - log.error( + LOG.error( "Caught exception trying to save entry to MD-SAL", e); } @@ -307,7 +284,7 @@ public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { version); tx.submit().checkedGet(); } catch (Exception e) { - log.error( + LOG.error( "Caught exception trying to save entry to MD-SAL", e); } @@ -320,10 +297,10 @@ public Future> vfLicenseModelUpdate(VfLice Properties parms = new Properties(); - log.info( SVC_OPERATION +" called." ); + LOG.info( SVC_OPERATION +" called." ); if(input == null ) { - log.debug("exiting " +SVC_OPERATION+ " because of invalid input"); + LOG.debug("exiting " +SVC_OPERATION+ " because of invalid input"); return null; } @@ -339,28 +316,24 @@ public Future> vfLicenseModelUpdate(VfLice errorMessage = "Artifact version already exists"; } else { // Translate input object into SLI-consumable properties - log.info("Adding INPUT data for "+SVC_OPERATION+" input: " + input); + 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")) + if (asdcApiSliClient.hasGraph("ASDC-API", SVC_OPERATION , null, "sync")) { try { - respProps = sliClient.execute("ASDC-API", SVC_OPERATION, null, "sync", parms); + respProps = asdcApiSliClient.execute("ASDC-API", SVC_OPERATION, null, "sync", parms); } catch (Exception e) { - log.error("Caught exception executing service logic for "+ SVC_OPERATION, e); + LOG.error("Caught exception executing service logic for "+ SVC_OPERATION, e); } } else { errorMessage = "No service logic active for ASDC-API: '" + SVC_OPERATION + "'"; @@ -371,7 +344,7 @@ public Future> vfLicenseModelUpdate(VfLice { errorCode = "500"; errorMessage = e.getMessage(); - log.error("Caught exception looking for service logic", e); + LOG.error("Caught exception looking for service logic", e); } @@ -384,14 +357,14 @@ public Future> vfLicenseModelUpdate(VfLice if ("200".equals(errorCode)) { - log.info("ASDC update succeeded"); + LOG.info("ASDC update succeeded"); // Update config tree applyVfLicenseModelUpdate(input); addArtifactVersion(input.getArtifactName(), input.getArtifactVersion()); } else { - log.info("ASDC update failed ("+errorCode+" : "+errorMessage); + LOG.info("ASDC update failed ("+errorCode+" : "+errorMessage); } // Send response 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 index 5b268bc2..51fdd700 100644 --- 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 @@ -25,39 +25,22 @@ 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 static final Logger LOG = LoggerFactory.getLogger(AsdcApiSliClient.class); - private SvcLogicService svcLogic = null; + private final SvcLogicService svcLogicService; - 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 AsdcApiSliClient(final SvcLogicService svcLogicService) { + this.svcLogicService = svcLogicService; } public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException { - return(svcLogic.hasGraph(module, rpc, version, mode)); + return(svcLogicService.hasGraph(module, rpc, version, mode)); } @@ -78,7 +61,7 @@ public class AsdcApiSliClient { } } - Properties respProps = svcLogic.execute(module, rpc, version, mode, parms); + Properties respProps = svcLogicService.execute(module, rpc, version, mode, parms); if (LOG.isDebugEnabled()) { 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 deleted file mode 100644 index 26dc9428..00000000 --- a/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModule.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============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========================================================= - */ - -package org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.asdcapi.provider.impl.rev140523; - -import org.onap.ccsdk.sli.northbound.asdcapi.AsdcApiProvider; - -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() { - - - 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/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 deleted file mode 100644 index 513e61cf..00000000 --- a/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModuleFactory.java +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * ============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========================================================= - */ - -/* -* 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/resources/initial/asdcApi-provider.xml b/asdcApi/provider/src/main/resources/initial/asdcApi-provider.xml deleted file mode 100644 index aefdec28..00000000 --- a/asdcApi/provider/src/main/resources/initial/asdcApi-provider.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - - - prefix:asdcApi-provider-impl - - asdcApi-provider-impl - - - - binding:binding-rpc-registry - binding-rpc-broker - - - - binding:binding-async-data-broker - binding-data-broker - - - - - binding:binding-notification-service - - binding-notification-broker - - - - - - - - - - - org:onap:ccsdk:sli:northbound:asdcapi:provider:impl?module=asdcApi-provider-impl&revision=2014-05-23 - - - diff --git a/asdcApi/provider/src/main/resources/org/opendaylight/blueprint/asdc-blueprint.xml b/asdcApi/provider/src/main/resources/org/opendaylight/blueprint/asdc-blueprint.xml new file mode 100644 index 00000000..6229db1f --- /dev/null +++ b/asdcApi/provider/src/main/resources/org/opendaylight/blueprint/asdc-blueprint.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/asdcApi/provider/src/main/yang/asdcApi-provider-impl.yang b/asdcApi/provider/src/main/yang/asdcApi-provider-impl.yang deleted file mode 100755 index 7a1876cc..00000000 --- a/asdcApi/provider/src/main/yang/asdcApi-provider-impl.yang +++ /dev/null @@ -1,61 +0,0 @@ -module asdcApi-provider-impl { - - yang-version 1; - namespace "org:onap:ccsdk:sli:northbound:asdcapi:provider:impl"; - prefix "asdcApi-provider-impl"; - - import config { prefix config; revision-date 2013-04-05; } - import opendaylight-md-sal-binding { prefix mdsal; revision-date 2013-10-28; } - - description - "This module contains the base YANG definitions for - asdcApi-provider impl implementation."; - - revision "2014-05-23" { - description - "Initial revision."; - } - - // This is the definition of the service implementation as a module identity. - identity asdcApi-provider-impl { - base config:module-type; - - // Specifies the prefix for generated java classes. - config:java-name-prefix AsdcApiProvider; - } - - // Augments the 'configuration' choice node under modules/module. - // We consume the three main services, RPCs, DataStore, and Notifications - augment "/config:modules/config:module/config:configuration" { - case asdcApi-provider-impl { - when "/config:modules/config:module/config:type = 'asdcApi-provider-impl'"; - - container rpc-registry { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity mdsal:binding-rpc-registry; - } - } - } - - container notification-service { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity mdsal:binding-notification-service; - } - } - } - - container data-broker { - uses config:service-ref { - refine type { - mandatory false; - config:required-identity mdsal:binding-async-data-broker; - } - } - } - } - } -} -- cgit 1.2.3-korg