diff options
author | ruilin cai <ruilin.cai@huawei.com> | 2023-05-25 13:02:58 -0400 |
---|---|---|
committer | Ruilin Cai <ruilin.cai@huawei.com> | 2023-06-20 18:02:29 +0000 |
commit | 13005406337c998f07d1b450d3ff6aa3d01b7ced (patch) | |
tree | 10783169e77f5715b5d6589776d9a2e7806e45c8 /actn-interface-tools | |
parent | 31512b50bcba5b865fa0107f4efd8f678ac9d430 (diff) |
[actn-interface-tools] Added global-app module. Deleted some unused comments. Changed some import expressions.
global-app module: this module is under global-control module which is parallel with global-api module. It is used to contain implementations of interfaces in global-api module. Those implementations are able to control the lifecycle of objects in this OSS actn sdk.
Change-Id: I2032b9485a0b625193cb0b22f960d4f8739efa77
Signed-off-by: ruilin cai <ruilin.cai@huawei.com>
Issue-ID: INT-2213
Signed-off-by: ruilin cai <ruilin.cai@huawei.com>
Diffstat (limited to 'actn-interface-tools')
8 files changed, 1004 insertions, 13 deletions
diff --git a/actn-interface-tools/global-control/app/pom.xml b/actn-interface-tools/global-control/app/pom.xml new file mode 100644 index 0000000..50a9dbc --- /dev/null +++ b/actn-interface-tools/global-control/app/pom.xml @@ -0,0 +1,105 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ ============LICENSE_START======================================================= + ~ Actn Interface Tools + ~ ================================================================================ + ~ Copyright (C) 2023 Huawei Canada Limited. + ~ ================================================================================ + ~ 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========================================================= + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.integration.ietf-actn-tools</groupId> + <artifactId>global-control</artifactId> + <version>1.0-SNAPSHOT</version> + + </parent> + <groupId>org.onap.integration.ietf-actn-tools</groupId> + <version>1.0-SNAPSHOT</version> + <artifactId>globalapp</artifactId> + + <properties> + <onos.app.name>org.onosproject.yang</onos.app.name> + <onos-yang-tools-version>2.6.1</onos-yang-tools-version> + </properties> + + <dependencies> + <dependency> + <groupId>org.onap.integration.ietf-actn-tools</groupId> + <artifactId>actn-model</artifactId> + <version>1.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-yang-model</artifactId> + <version>${onos-yang-tools-version}</version> + </dependency> + + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-yang-runtime</artifactId> + <version>${onos-yang-tools-version}</version> + </dependency> + + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-yang-serializers-xml</artifactId> + <version>${onos-yang-tools-version}</version> + </dependency> + + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-yang-serializers-json</artifactId> + <version>${onos-yang-tools-version}</version> + + </dependency> + + <dependency> + <groupId>org.apache.karaf.shell</groupId> + <artifactId>org.apache.karaf.shell.console</artifactId> + <scope>provided</scope> + <version>3.0.8</version> + </dependency> + <dependency> + <groupId>org.onap.integration.ietf-actn-tools</groupId> + <artifactId>actn-client</artifactId> + <version>1.0-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.onap.integration.ietf-actn-tools</groupId> + <artifactId>globalapi</artifactId> + <version>1.0-SNAPSHOT</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>com.google.auto.service</groupId> + <artifactId>auto-service</artifactId> + <version>1.0</version> + </dependency> + <dependency> + <groupId>org.onap.integration.ietf-actn-tools</groupId> + <artifactId>yang-utils</artifactId> + <version>1.0-SNAPSHOT</version> + <scope>compile</scope> + </dependency> + + + </dependencies> + + +</project> diff --git a/actn-interface-tools/global-control/app/src/main/java/org/onap/integration/actninterfacetools/globalapp/AbstractYangModelRegistrator.java b/actn-interface-tools/global-control/app/src/main/java/org/onap/integration/actninterfacetools/globalapp/AbstractYangModelRegistrator.java new file mode 100644 index 0000000..6dba1e5 --- /dev/null +++ b/actn-interface-tools/global-control/app/src/main/java/org/onap/integration/actninterfacetools/globalapp/AbstractYangModelRegistrator.java @@ -0,0 +1,102 @@ +/* + * ============LICENSE_START======================================================= + * Actn Interface Tools + * ================================================================================ + * Copyright (C) 2023 Huawei Canada Limited. + * ================================================================================ + * 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.integration.actninterfacetools.globalapp; + +import org.onap.integration.actninterfacetools.globalapp.impl.GlobalServiceUtil; +import org.onosproject.yang.model.YangModel; +import org.onosproject.yang.model.YangModuleId; +import org.onosproject.yang.runtime.AppModuleInfo; +import org.onosproject.yang.runtime.DefaultModelRegistrationParam; +import org.onosproject.yang.runtime.ModelRegistrationParam; +import org.onosproject.yang.runtime.ModelRegistrationParam.Builder; +import org.onosproject.yang.runtime.YangModelRegistry; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.net.URISyntaxException; +import java.util.Map; + +/** + * Abstract base for self-registering YANG models. + */ + +public abstract class AbstractYangModelRegistrator { + + private final Logger log = LoggerFactory.getLogger(getClass()); + private final Class<?> loaderClass; + + private Map<YangModuleId, AppModuleInfo> appInfo; + protected YangModel model; + private ModelRegistrationParam registrationParam; + + protected YangModelRegistry modelRegistry = GlobalServiceUtil.getNewGlobalService(); + protected YangClassLoaderRegistry sourceResolver = GlobalServiceUtil.getNewGlobalService(); + + /** + * Creates a model registrator primed with the class-loader of the specified + * class. + * + * @param loaderClass class whose class loader is to be used for locating + * schema data + */ + protected AbstractYangModelRegistrator(Class<?> loaderClass) { + this.loaderClass = loaderClass; + } + + /** + * Creates a model registrator primed with the class-loader of the specified + * class and application info. + * + * @param loaderClass class whose class loader is to be used for locating + * schema data + * @param appInfo application information + */ + protected AbstractYangModelRegistrator(Class<?> loaderClass, + Map<YangModuleId, AppModuleInfo> appInfo) { + this.loaderClass = loaderClass; + this.appInfo = appInfo; + } + + + public void activate() throws URISyntaxException { + model = YangManagerUtils.getYangModel(loaderClass); + ModelRegistrationParam.Builder b = + DefaultModelRegistrationParam.builder().setYangModel(model); + registrationParam = getAppInfo(b).setYangModel(model).build(); + sourceResolver.registerClassLoader(model.getYangModelId(), loaderClass.getClassLoader()); + modelRegistry.registerModel(registrationParam); + log.info("Yang Model Registration Finished"); + } + + protected ModelRegistrationParam.Builder getAppInfo(Builder b) { + if (appInfo != null) { + appInfo.entrySet().stream().filter( + entry -> model.getYangModule(entry.getKey()) != null).forEach( + entry -> b.addAppModuleInfo(entry.getKey(), entry.getValue())); + } + return b; + } + + protected void deactivate() { + modelRegistry.unregisterModel(registrationParam); + sourceResolver.unregisterClassLoader(model.getYangModelId()); + log.info("Stopped"); + } +} diff --git a/actn-interface-tools/global-control/app/src/main/java/org/onap/integration/actninterfacetools/globalapp/ActnModelRegistrator.java b/actn-interface-tools/global-control/app/src/main/java/org/onap/integration/actninterfacetools/globalapp/ActnModelRegistrator.java new file mode 100644 index 0000000..5b34e88 --- /dev/null +++ b/actn-interface-tools/global-control/app/src/main/java/org/onap/integration/actninterfacetools/globalapp/ActnModelRegistrator.java @@ -0,0 +1,137 @@ +/* + * ============LICENSE_START======================================================= + * Actn Interface Tools + * ================================================================================ + * Copyright (C) 2023 Huawei Canada Limited. + * ================================================================================ + * 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.integration.actninterfacetools.globalapp; + + +import com.google.common.collect.ImmutableMap; +import org.apache.felix.scr.annotations.Component; +import org.onosproject.yang.gen.v1.ietfethtetopology.rev20191118.IetfEthTeTopology; +import org.onosproject.yang.gen.v1.ietfethtetunnel.rev20180301.IetfEthTeTunnel; +import org.onosproject.yang.gen.v1.ietfinettypes.rev20210222.IetfInetTypes; +import org.onosproject.yang.gen.v1.ietfroutingtypes.rev20171204.IetfRoutingTypes; +import org.onosproject.yang.gen.v1.ietfyangtypes.rev20210414.IetfYangTypes; +import org.onosproject.yang.gen.v11.ietfethtranservice.rev20210111.IetfEthTranService; +import org.onosproject.yang.gen.v11.ietfethtrantypes.rev20191103.IetfEthTranTypes; +import org.onosproject.yang.gen.v11.ietflayer1types.rev20210219.IetfLayer1Types; +import org.onosproject.yang.gen.v11.ietfnetwork.rev20180226.IetfNetwork; +import org.onosproject.yang.gen.v11.ietfnetworktopology.rev20180226.IetfNetworkTopology; +import org.onosproject.yang.gen.v11.ietfopticalslice.rev20200821.IetfOpticalSlice; +import org.onosproject.yang.gen.v11.ietfotntopology.rev20210222.IetfOtnTopology; +import org.onosproject.yang.gen.v11.ietfotntunnel.rev20210625.IetfOtnTunnel; +import org.onosproject.yang.gen.v11.ietfte.rev20210220.IetfTe; +import org.onosproject.yang.gen.v11.ietftetopology.rev20200806.IetfTeTopology; +import org.onosproject.yang.gen.v11.ietftetypes.rev20200610.IetfTeTypes; +import org.onosproject.yang.model.YangModel; +import org.onosproject.yang.model.YangModuleId; +import org.onosproject.yang.runtime.AppModuleInfo; +import org.onosproject.yang.runtime.DefaultAppModuleInfo; + +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +/** + * Representation of TE Topology YANG model registrator. + */ +public class ActnModelRegistrator extends AbstractYangModelRegistrator { + /** + * Creates ACTN YANG model registrator. + */ + public ActnModelRegistrator() throws URISyntaxException { + super(IetfTeTopology.class, getAppInfo()); + } + + private static Map<YangModuleId, AppModuleInfo> getAppInfo() throws URISyntaxException { + Map<YangModuleId, AppModuleInfo> appInfo = new HashMap<>(); + YangModel model = YangManagerUtils.getYangModel(IetfTeTopology.class); + Iterator<YangModuleId> it = model.getYangModulesId().iterator(); + YangModuleId id; + while (it.hasNext()) { + id = it.next(); + switch (id.moduleName()) { + case "ietf-inet-types": + appInfo.put(id, new DefaultAppModuleInfo(IetfInetTypes.class, null)); + break; + + case "ietf-network": + appInfo.put(id, new DefaultAppModuleInfo(IetfNetwork.class, null)); + break; + case "ietf-network-topology": + appInfo.put(id, new DefaultAppModuleInfo(IetfNetworkTopology.class, null)); + break; + + case "ietf-yang-types": + appInfo.put(id, new DefaultAppModuleInfo(IetfYangTypes.class, null)); + break; + case "ietf-routing-types": + appInfo.put(id, new DefaultAppModuleInfo(IetfRoutingTypes.class, null)); + break; + case "ietf-te-types": + appInfo.put(id, new DefaultAppModuleInfo(IetfTeTypes.class, null)); + break; + + + + case "ietf-te-topology": + appInfo.put(id, new DefaultAppModuleInfo(IetfTeTopology.class, null)); + break; + case "ietf-otn-topology": + appInfo.put(id, new DefaultAppModuleInfo(IetfOtnTopology.class, null)); + break; + + case "ietf-eth-tran-types": + appInfo.put(id, new DefaultAppModuleInfo(IetfEthTranTypes.class, null)); + break; + case "ietf-eth-te-topology": + appInfo.put(id, new DefaultAppModuleInfo(IetfEthTeTopology.class, null)); + break; + + + case "ietf-te": + appInfo.put(id, new DefaultAppModuleInfo(IetfTe.class, null)); + break; + + case "ietf-otn-tunnel": + appInfo.put(id, new DefaultAppModuleInfo(IetfOtnTunnel.class, null)); + break; + case "ietf-eth-te-tunnel": + appInfo.put(id, new DefaultAppModuleInfo(IetfEthTeTunnel.class, null)); + break; + + + case "ietf-optical-slice": + appInfo.put(id, new DefaultAppModuleInfo(IetfOpticalSlice.class,null)); + break; + case "ietf-layer1-types": + appInfo.put(id, new DefaultAppModuleInfo(IetfLayer1Types.class,null)); + break; + case "ietf-eth-tran-service": + appInfo.put(id, new DefaultAppModuleInfo(IetfEthTranService.class,null)); + break; + default: + break; + } + } + + return ImmutableMap.copyOf(appInfo); + } +} diff --git a/actn-interface-tools/global-control/app/src/main/java/org/onap/integration/actninterfacetools/globalapp/YangClassLoaderRegistry.java b/actn-interface-tools/global-control/app/src/main/java/org/onap/integration/actninterfacetools/globalapp/YangClassLoaderRegistry.java new file mode 100644 index 0000000..fd35e46 --- /dev/null +++ b/actn-interface-tools/global-control/app/src/main/java/org/onap/integration/actninterfacetools/globalapp/YangClassLoaderRegistry.java @@ -0,0 +1,54 @@ +/* + * ============LICENSE_START======================================================= + * Actn Interface Tools + * ================================================================================ + * Copyright (C) 2023 Huawei Canada Limited. + * ================================================================================ + * 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.integration.actninterfacetools.globalapp; + +/** + * Auxiliary mechanism for resolving model IDs into class-loaders from where + * the model was registered to allow access to model-specific resources. + * + * Note: Consider promoting this to ONOS YANG Tools repo. + */ + +public interface YangClassLoaderRegistry { + + /** + * Get the class loader registered for the given model id. + * + * @param modelId model identifier + * @return class loader registered for the model + */ + ClassLoader getClassLoader(String modelId); + + /** + * Register the class loader for the specified model. + * + * @param modelId model identifier + * @param classLoader class loader + */ + void registerClassLoader(String modelId, ClassLoader classLoader); + + /** + * Register the class loader for the specified model. + * + * @param modelId model identifier + */ + void unregisterClassLoader(String modelId); +} diff --git a/actn-interface-tools/global-control/app/src/main/java/org/onap/integration/actninterfacetools/globalapp/YangManagerUtils.java b/actn-interface-tools/global-control/app/src/main/java/org/onap/integration/actninterfacetools/globalapp/YangManagerUtils.java new file mode 100644 index 0000000..d3a3dba --- /dev/null +++ b/actn-interface-tools/global-control/app/src/main/java/org/onap/integration/actninterfacetools/globalapp/YangManagerUtils.java @@ -0,0 +1,118 @@ +/* + * ============LICENSE_START======================================================= + * Actn Interface Tools + * ================================================================================ + * Copyright (C) 2023 Huawei Canada Limited. + * ================================================================================ + * 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.integration.actninterfacetools.globalapp; + +import org.onosproject.yang.compiler.tool.YangCompilerManager; +import org.onosproject.yang.compiler.tool.YangNodeInfo; +import org.onosproject.yang.model.YangModel; +import org.onosproject.yang.runtime.helperutils.YangApacheUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; + +public class YangManagerUtils { + private static final String SLASH; + private static final String HYPHEN = "-"; + private static final String PERIOD = "."; + private static final String YANG_RESOURCES = "yang/resources"; + private static final String SYSTEM; + private static final String MAVEN = "mvn:"; + private static final String JAR = ".jar"; + private static final String USER_DIRECTORY = "user.dir"; + private static final Logger log; + + private YangManagerUtils() { + } + public static YangModel getYangModel(Class<?> modClass) throws URISyntaxException { + String jarPath = new File(YangManagerUtils.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getPath(); + String yangModelPath = jarPath.replaceAll("/global-control/app/target/classes", "/actn-model/target/actn-model-1.0-SNAPSHOT"); + List<YangNodeInfo> nodeInfo = new ArrayList(); +// System.out.println(yangModelPath); + String metaPath = yangModelPath + SLASH + "yang/resources" + SLASH; + YangModel model = processJarParsingOperations(yangModelPath); + if (model != null) { + YangCompilerManager.setNodeInfo(model, nodeInfo); + if (!nodeInfo.isEmpty()) { + return YangCompilerManager.processYangModel(metaPath, nodeInfo, model.getYangModelId(), false); + } + } + + return null; + } + private static String getJarPathFromBundleLocation(String mvnLocationPath, String currentDirectory) { + StringBuilder builder = new StringBuilder(); + builder.append(currentDirectory).append(SYSTEM); + StringBuilder ver = new StringBuilder(); + if (mvnLocationPath.contains("mvn:")) { + String[] strArray = mvnLocationPath.replaceFirst("\\$Bundle-.*$", "").split("mvn:"); + if (strArray[1].contains(File.separator)) { + String[] split = strArray[1].split(File.separator); + if (split[0].contains(".")) { + String[] groupId = split[0].split(Pattern.quote(".")); + String[] var7 = groupId; + int var8 = groupId.length; + + for(int var9 = 0; var9 < var8; ++var9) { + String s = var7[var9]; + builder.append(s).append(SLASH); + } + + for(int i = 1; i < split.length; ++i) { + builder.append(split[i]).append(SLASH); + ver.append(split[i]).append("-"); + } + + builder.append(ver); + builder.deleteCharAt(builder.length() - 1); + return builder.toString(); + } + } + } + + return null; + } + + private static YangModel processJarParsingOperations(String path) { + String jar = path + ".jar"; + + try { + File file = new File(jar); + if (file.exists()) { + return YangCompilerManager.parseJarFile(path + ".jar", path); + } + } catch (IOException var3) { + log.error(" failed to parse the jar file in path {} : {} ", path, var3.getMessage()); + } + + return null; + } + + static { + SLASH = File.separator; + SYSTEM = SLASH + "system" + SLASH; + log = LoggerFactory.getLogger(YangApacheUtils.class); + } +} diff --git a/actn-interface-tools/global-control/app/src/main/java/org/onap/integration/actninterfacetools/globalapp/impl/GlobalServiceImpl.java b/actn-interface-tools/global-control/app/src/main/java/org/onap/integration/actninterfacetools/globalapp/impl/GlobalServiceImpl.java new file mode 100644 index 0000000..33df725 --- /dev/null +++ b/actn-interface-tools/global-control/app/src/main/java/org/onap/integration/actninterfacetools/globalapp/impl/GlobalServiceImpl.java @@ -0,0 +1,212 @@ +/* + * ============LICENSE_START======================================================= + * Actn Interface Tools + * ================================================================================ + * Copyright (C) 2023 Huawei Canada Limited. + * ================================================================================ + * 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.integration.actninterfacetools.globalapp.impl; + +import com.google.auto.service.AutoService; +import org.onap.integration.actninterfacetools.actnclient.impl.ActnClientServiceImpl; +import org.onap.integration.actninterfacetools.globalapi.ActnClientService; +import org.onap.integration.actninterfacetools.globalapi.ActnDataConverter; +import org.onap.integration.actninterfacetools.globalapi.GlobalService; +import org.onap.integration.actninterfacetools.globalapp.YangClassLoaderRegistry; +import org.onosproject.yang.model.ModelConverter; +import org.onosproject.yang.model.ModelObjectData; +import org.onosproject.yang.model.ResourceData; +import org.onosproject.yang.model.SchemaContextProvider; +import org.onosproject.yang.model.SchemaContext; +import org.onosproject.yang.model.ResourceId; +import org.onosproject.yang.model.RpcContext; +import org.onosproject.yang.model.ModelObjectId; +import org.onosproject.yang.model.YangModel; +import org.onosproject.yang.model.YangModule; +import org.onosproject.yang.model.YangModuleId; +import org.onosproject.yang.runtime.ModelRegistrationParam; +import org.onosproject.yang.runtime.YangModelRegistry; +import org.onosproject.yang.runtime.YangRuntimeService; +import org.onosproject.yang.runtime.YangSerializerRegistry; +import org.onosproject.yang.runtime.CompositeData; +import org.onosproject.yang.runtime.CompositeStream; +import org.onosproject.yang.runtime.RuntimeContext; +import org.onosproject.yang.runtime.YangSerializer; +import org.onosproject.yang.runtime.impl.DefaultModelConverter; +import org.onosproject.yang.runtime.impl.DefaultYangModelRegistry; +import org.onosproject.yang.runtime.impl.DefaultYangRuntimeHandler; +import org.onosproject.yang.runtime.impl.DefaultYangSerializerRegistry; +import org.onosproject.yang.runtime.impl.DefaultSchemaContextProvider; + +import java.net.URISyntaxException; +import java.util.Map; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; +@AutoService(GlobalService.class) +public class GlobalServiceImpl implements GlobalService, YangModelRegistry, + YangSerializerRegistry, YangRuntimeService, ModelConverter, + SchemaContextProvider, YangClassLoaderRegistry { + private static volatile GlobalServiceImpl globalService = null; + private static GlobalServiceUtil globalServiceUtil= GlobalServiceUtil.getNewGlobalService(); + + public GlobalServiceImpl() { + } + public static GlobalServiceImpl getNewGlobalService(){ + if(globalService != null){ + return globalService; + } + synchronized (ActnClientServiceImpl.class) { + if(globalService == null){ + globalService = new GlobalServiceImpl(); + + } + return globalService; + } + } + + @Override + public String getServiceName() { + return "GlobalServiceImpl"; + } + + @Override + public void initialize() throws URISyntaxException { + globalServiceUtil.initialize(); + } + + @Override + public ActnClientService getActnClientService(ActnDataConverter actnDataConverter) throws URISyntaxException { + return globalServiceUtil.getActnClientService(actnDataConverter); + } + + public DefaultYangModelRegistry getModelRegistry(){ + + return globalServiceUtil.getModelRegistry(); + } + public DefaultYangSerializerRegistry getSerializerRegistry(){ + return globalServiceUtil.getSerializerRegistry(); + } + public DefaultYangRuntimeHandler getRuntimeService(){ + return globalServiceUtil.getRuntimeService(); + } + public DefaultModelConverter getModelConverter(){ + return globalServiceUtil.getModelConverter(); + } + public DefaultSchemaContextProvider getSchemaContextProvider(){ + return globalServiceUtil.getSchemaContextProvider(); + } + + public Map<String, ClassLoader> getClassLoaders(){ + return globalServiceUtil.getClassLoaders(); + } + + + @Override + public ClassLoader getClassLoader(String modelId) { + return globalServiceUtil.getClassLoader(modelId); + } + + @Override + public void registerClassLoader(String modelId, ClassLoader classLoader) { + globalServiceUtil.registerClassLoader(modelId, classLoader); + } + + @Override + public void unregisterClassLoader(String modelId) { + globalServiceUtil.unregisterClassLoader(modelId); + } + + @Override + public ModelObjectData createModel(ResourceData resourceData) { + return globalServiceUtil.createModel(resourceData); + } + + @Override + public ResourceData createDataNode(ModelObjectData modelObjectData) { + return globalServiceUtil.createDataNode(modelObjectData); + } + + @Override + public SchemaContext getSchemaContext(ResourceId resourceId) { + return globalServiceUtil.getSchemaContext(resourceId); + } + + @Override + public RpcContext getRpcContext(ResourceId resourceId) { + return globalServiceUtil.getRpcContext(resourceId); + } + + @Override + public void registerModel(ModelRegistrationParam modelRegistrationParam) throws IllegalArgumentException { + globalServiceUtil.registerModel(modelRegistrationParam); + } + + + @Override + public void registerAnydataSchema(ModelObjectId parentModId, ModelObjectId childModId) throws IllegalArgumentException { + globalServiceUtil.registerAnydataSchema(parentModId, childModId); + } + + @Override + public void unregisterAnydataSchema(Class parentClass, Class childClass) throws IllegalArgumentException { + globalServiceUtil.unregisterAnydataSchema(parentClass, childClass); + } + + @Override + public void unregisterModel(ModelRegistrationParam modelRegistrationParam) { + globalServiceUtil.unregisterModel(modelRegistrationParam); + } + + @Override + public Set<YangModel> getModels() { + return globalServiceUtil.getModels(); + } + + @Override + public YangModel getModel(String s) { + return globalServiceUtil.getModel(s); + } + + @Override + public YangModule getModule(YangModuleId yangModuleId) { + return globalServiceUtil.getModule(yangModuleId); + } + + @Override + public CompositeData decode(CompositeStream cs, RuntimeContext rc) { + return globalServiceUtil.decode(cs, rc); + } + + @Override + public CompositeStream encode(CompositeData cd, RuntimeContext rc) { + return globalServiceUtil.encode(cd, rc); + } + + @Override + public void registerSerializer(YangSerializer ys) { + globalServiceUtil.registerSerializer(ys); + } + + @Override + public void unregisterSerializer(YangSerializer ys) { + globalServiceUtil.unregisterSerializer(ys); + } + + @Override + public Set<YangSerializer> getSerializers() { + return globalServiceUtil.getSerializers(); + } +} diff --git a/actn-interface-tools/global-control/app/src/main/java/org/onap/integration/actninterfacetools/globalapp/impl/GlobalServiceUtil.java b/actn-interface-tools/global-control/app/src/main/java/org/onap/integration/actninterfacetools/globalapp/impl/GlobalServiceUtil.java new file mode 100644 index 0000000..899a794 --- /dev/null +++ b/actn-interface-tools/global-control/app/src/main/java/org/onap/integration/actninterfacetools/globalapp/impl/GlobalServiceUtil.java @@ -0,0 +1,272 @@ +/* + * ============LICENSE_START======================================================= + * Actn Interface Tools + * ================================================================================ + * Copyright (C) 2023 Huawei Canada Limited. + * ================================================================================ + * 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.integration.actninterfacetools.globalapp.impl; + +import com.google.auto.service.AutoService; +import org.onap.integration.actninterfacetools.actnclient.impl.ActnClientServiceImpl; +import org.onap.integration.actninterfacetools.globalapi.ActnClientService; +import org.onap.integration.actninterfacetools.globalapi.ActnDataConverter; +import org.onap.integration.actninterfacetools.globalapi.GlobalService; +import org.onap.integration.actninterfacetools.globalapp.AbstractYangModelRegistrator; +import org.onap.integration.actninterfacetools.globalapp.ActnModelRegistrator; +import org.onap.integration.actninterfacetools.globalapp.YangClassLoaderRegistry; +import org.onap.integration.actninterfacetools.yangutils.CodecConverter; +import org.onap.integration.actninterfacetools.yangutils.YangToolsUtil; +import org.onosproject.yang.model.ModelConverter; +import org.onosproject.yang.model.ModelObjectData; +import org.onosproject.yang.model.ResourceData; +import org.onosproject.yang.model.SchemaContextProvider; +import org.onosproject.yang.model.SchemaContext; +import org.onosproject.yang.model.ResourceId; +import org.onosproject.yang.model.RpcContext; +import org.onosproject.yang.model.ModelObjectId; +import org.onosproject.yang.model.YangModel; +import org.onosproject.yang.model.YangModule; +import org.onosproject.yang.model.YangModuleId; +import org.onosproject.yang.model.NodeKey; +import org.onosproject.yang.runtime.ModelRegistrationParam; +import org.onosproject.yang.runtime.YangModelRegistry; +import org.onosproject.yang.runtime.YangRuntimeService; +import org.onosproject.yang.runtime.YangSerializerRegistry; +import org.onosproject.yang.runtime.CompositeData; +import org.onosproject.yang.runtime.CompositeStream; +import org.onosproject.yang.runtime.RuntimeContext; +import org.onosproject.yang.runtime.YangSerializer; +import org.onosproject.yang.runtime.impl.DefaultModelConverter; +import org.onosproject.yang.runtime.impl.DefaultYangModelRegistry; +import org.onosproject.yang.runtime.impl.DefaultYangRuntimeHandler; +import org.onosproject.yang.runtime.impl.DefaultYangSerializerRegistry; +import org.onosproject.yang.runtime.impl.DefaultSchemaContextProvider; +import org.onosproject.yang.serializers.json.JsonSerializer; +import org.onosproject.yang.serializers.xml.XmlSerializer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.net.URISyntaxException; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +import static com.google.common.base.Preconditions.checkNotNull; + + +public class GlobalServiceUtil implements YangModelRegistry, + YangSerializerRegistry, YangRuntimeService, ModelConverter, + SchemaContextProvider, YangClassLoaderRegistry { + private static volatile GlobalServiceUtil globalServiceInstance = null; + private static Map<ActnDataConverter, ActnClientService> dataConverter2ActnClientServiceMap = new ConcurrentHashMap(); + private static volatile boolean initialized = false; + private static final String APP_ID = "org.onosproject.yang"; + private static final Logger log = LoggerFactory.getLogger(GlobalServiceUtil.class); + private static volatile DefaultYangModelRegistry modelRegistry = null; + private static volatile DefaultYangSerializerRegistry serializerRegistry = null; + private static volatile DefaultYangRuntimeHandler runtimeService = null; + private static volatile DefaultModelConverter modelConverter = null; + private static volatile DefaultSchemaContextProvider schemaContextProvider = null; + + private static Map<String, ClassLoader> classLoaders = null; + private GlobalServiceUtil(){ + } + public String getServiceName(){ + return "GlobalServiceUtil"; + } + public static GlobalServiceUtil getNewGlobalService(){ + if(globalServiceInstance != null){ + return globalServiceInstance; + } + synchronized (ActnClientServiceImpl.class) { + if(globalServiceInstance == null){ + globalServiceInstance = new GlobalServiceUtil(); + + } + return globalServiceInstance; + } + } + + + public synchronized void initialize() throws URISyntaxException { + if(!initialized){ + if(serializerRegistry == null){ + serializerRegistry = new DefaultYangSerializerRegistry(); + } + if(modelRegistry == null){ + modelRegistry = new DefaultYangModelRegistry(); + } + if(runtimeService == null){ + runtimeService = new DefaultYangRuntimeHandler(serializerRegistry, modelRegistry); + } + if(schemaContextProvider == null){ + schemaContextProvider = new DefaultSchemaContextProvider(modelRegistry); + } + serializerRegistry.registerSerializer(new JsonSerializer()); + serializerRegistry.registerSerializer(new XmlSerializer()); + if(modelConverter == null){ + modelConverter = new DefaultModelConverter(modelRegistry); + } + if(classLoaders == null){ + classLoaders = new ConcurrentHashMap<>(); + } + AbstractYangModelRegistrator abstractYangModelRegistrator = new ActnModelRegistrator(); + abstractYangModelRegistrator.activate(); + CodecConverter.active(); + YangToolsUtil.active(); + log.info("Initialization Finished"); + initialized = true; + } + } + + + public synchronized ActnClientService getActnClientService(ActnDataConverter actnDataConverter) throws URISyntaxException { + if(!initialized){ + initialize(); + } + if(dataConverter2ActnClientServiceMap.get(actnDataConverter)!=null){ + return dataConverter2ActnClientServiceMap.get(actnDataConverter); + }else{ + ActnClientService actnClientService = new ActnClientServiceImpl(actnDataConverter); + dataConverter2ActnClientServiceMap.put(actnDataConverter, actnClientService); + return actnClientService; + } + } + + public DefaultYangModelRegistry getModelRegistry(){ + return modelRegistry; + } + public DefaultYangSerializerRegistry getSerializerRegistry(){ + return serializerRegistry; + } + public DefaultYangRuntimeHandler getRuntimeService(){ + return runtimeService; + } + public DefaultModelConverter getModelConverter(){ + return modelConverter; + } + public DefaultSchemaContextProvider getSchemaContextProvider(){ + return schemaContextProvider; + } + + public Map<String, ClassLoader> getClassLoaders(){ + return classLoaders; + } + + + @Override + public ClassLoader getClassLoader(String modelId) { + return classLoaders.get(modelId); + } + + @Override + public void registerClassLoader(String modelId, ClassLoader classLoader) { + classLoaders.put(modelId, classLoader); + } + + @Override + public void unregisterClassLoader(String modelId) { + classLoaders.remove(modelId); + } + + @Override + public ModelObjectData createModel(ResourceData resourceData) { + return modelConverter.createModel(resourceData); + } + + @Override + public ResourceData createDataNode(ModelObjectData modelObjectData) { + return modelConverter.createDataNode(modelObjectData); + } + + @Override + public SchemaContext getSchemaContext(ResourceId resourceId) { + checkNotNull(resourceId, " resource id can't be null."); + NodeKey key = resourceId.nodeKeys().get(0); + if (resourceId.nodeKeys().size() == 1 && + "/".equals(key.schemaId().name())) { + return modelRegistry; + } + log.info("To be implemented."); + return null; + } + + @Override + public RpcContext getRpcContext(ResourceId resourceId) { + return schemaContextProvider.getRpcContext(resourceId); + } + + @Override + public void registerModel(ModelRegistrationParam modelRegistrationParam) throws IllegalArgumentException { + modelRegistry.registerModel(modelRegistrationParam); + } + + + @Override + public void registerAnydataSchema(ModelObjectId parentModId, ModelObjectId childModId) throws IllegalArgumentException { + modelRegistry.registerAnydataSchema(parentModId, childModId); + } + + @Override + public void unregisterAnydataSchema(Class parentClass, Class childClass) throws IllegalArgumentException { + modelRegistry.unregisterAnydataSchema(parentClass, childClass); + } + + @Override + public void unregisterModel(ModelRegistrationParam modelRegistrationParam) { + modelRegistry.unregisterModel(modelRegistrationParam); + } + + @Override + public Set<YangModel> getModels() { + return modelRegistry.getModels(); + } + + @Override + public YangModel getModel(String s) { + return modelRegistry.getModel(s); + } + + @Override + public YangModule getModule(YangModuleId yangModuleId) { + return modelRegistry.getModule(yangModuleId); + } + + @Override + public CompositeData decode(CompositeStream cs, RuntimeContext rc) { + return runtimeService.decode(cs, rc); + } + + @Override + public CompositeStream encode(CompositeData cd, RuntimeContext rc) { + return runtimeService.encode(cd, rc); + } + + @Override + public void registerSerializer(YangSerializer ys) { + serializerRegistry.registerSerializer(ys); + } + + @Override + public void unregisterSerializer(YangSerializer ys) { + serializerRegistry.unregisterSerializer(ys); + } + + @Override + public Set<YangSerializer> getSerializers() { + return serializerRegistry.getSerializers(); + } +} diff --git a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/ActnInterface.java b/actn-interface-tools/global-control/app/src/main/java/org/onap/integration/actninterfacetools/globalapp/package-info.java index 5325807..4cdfdc2 100644..100755 --- a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/ActnInterface.java +++ b/actn-interface-tools/global-control/app/src/main/java/org/onap/integration/actninterfacetools/globalapp/package-info.java @@ -17,17 +17,8 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.integration.actninterfacetools.actnclient.api; - -public interface ActnInterface { - CustomerTopology getNetworkTopology(String topologyId); - - void createOtnTunnel(CustomerOtnTunnel customerOtnTunnel); - - CustomerOtnTunnel getOtnTunnel(String actnOtnTunnelId); - - void createEthService(CustomerEthService customerEthService); - - CustomerEthService getEthService(String actnEthServiceId); -} +/** + * Base application to bring in the YANG libraries and assemble them for other apps to use. + */ +package org.onap.integration.actninterfacetools.globalapp;
\ No newline at end of file |