NSSMF adapter AAI client 73/102473/1
authorjananib <janani.b@huawei.com>
Thu, 27 Feb 2020 09:49:15 +0000 (15:19 +0530)
committerjananib <janani.b@huawei.com>
Thu, 27 Feb 2020 09:49:15 +0000 (15:19 +0530)
Adding AAI client to NSSMF adapter

Change-Id: I0c96c574a294f1e0ee142e5a60459b59824caf35
Issue-ID: SO-2544
Signed-off-by: jananib <janani.b@huawei.com>
adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiClientPropertiesImpl.java [new file with mode: 0644]
adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiClientProvider.java [new file with mode: 0644]
adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiServiceProvider.java [new file with mode: 0644]
adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiServiceProviderImpl.java [new file with mode: 0644]

diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiClientPropertiesImpl.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiClientPropertiesImpl.java
new file mode 100644 (file)
index 0000000..3333c64
--- /dev/null
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. 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.so.adapters.nssmf.extclients.aai;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import org.onap.so.client.aai.AAIProperties;
+import org.onap.so.client.aai.AAIVersion;
+import org.onap.so.spring.SpringContextHelper;
+import org.springframework.context.ApplicationContext;
+
+public class AaiClientPropertiesImpl implements AAIProperties {
+
+    private final String endpoint;
+
+    private final String encryptedBasicAuth;
+
+    private final String encrytptionKey;
+
+    public AaiClientPropertiesImpl() {
+        final ApplicationContext context = SpringContextHelper.getAppContext();
+        this.endpoint = context.getEnvironment().getProperty("aai.endpoint");
+        this.encryptedBasicAuth = context.getEnvironment().getProperty("aai.auth");
+        this.encrytptionKey = context.getEnvironment().getProperty("mso.key");
+    }
+
+    @Override
+    public AAIVersion getDefaultVersion() {
+        return AAIVersion.LATEST;
+    }
+
+    @Override
+    public String getAuth() {
+        return encryptedBasicAuth;
+    }
+
+    @Override
+    public String getKey() {
+        return encrytptionKey;
+    }
+
+    @Override
+    public URL getEndpoint() throws MalformedURLException {
+        return new URL(endpoint);
+    }
+
+    @Override
+    public String getSystemName() {
+        return "MSO";
+    }
+}
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiClientProvider.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiClientProvider.java
new file mode 100644 (file)
index 0000000..48e3ef1
--- /dev/null
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. 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.so.adapters.nssmf.extclients.aai;
+
+import org.onap.so.client.aai.AAIResourcesClient;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class AaiClientProvider {
+
+    @Bean
+    public AAIResourcesClient getAaiClient() {
+        return new AAIResourcesClient();
+    }
+}
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiServiceProvider.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiServiceProvider.java
new file mode 100644 (file)
index 0000000..c737ba6
--- /dev/null
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. 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.so.adapters.nssmf.extclients.aai;
+
+import org.onap.aai.domain.yang.EsrSystemInfoList;
+import org.onap.aai.domain.yang.EsrThirdpartySdncList;
+
+public interface AaiServiceProvider {
+
+    EsrThirdpartySdncList invokeGetThirdPartySdncList();
+
+    EsrSystemInfoList invokeGetThirdPartySdncEsrSystemInfo(String sdncId);
+
+}
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiServiceProviderImpl.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiServiceProviderImpl.java
new file mode 100644 (file)
index 0000000..f8422e2
--- /dev/null
@@ -0,0 +1,66 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. 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.so.adapters.nssmf.extclients.aai;
+
+
+import org.onap.aai.domain.yang.EsrSystemInfoList;
+import org.onap.aai.domain.yang.EsrThirdpartySdncList;
+import org.onap.so.client.aai.AAIObjectType;
+import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class AaiServiceProviderImpl implements AaiServiceProvider {
+
+    private static final Logger logger = LoggerFactory.getLogger(AaiServiceProviderImpl.class);
+
+    private final AaiClientProvider aaiClientProvider;
+
+    @Autowired
+    public AaiServiceProviderImpl(final AaiClientProvider aaiClientProvider) {
+        this.aaiClientProvider = aaiClientProvider;
+    }
+
+    @Override
+    public EsrThirdpartySdncList invokeGetThirdPartySdncList() {
+        return aaiClientProvider.getAaiClient()
+                .get(EsrThirdpartySdncList.class, AAIUriFactory.createResourceUri(AAIObjectType.THIRDPARTY_SDNC_LIST))
+                .orElseGet(() -> {
+                    logger.debug("No VNFMs in AAI");
+                    return null;
+                });
+    }
+
+    @Override
+    public EsrSystemInfoList invokeGetThirdPartySdncEsrSystemInfo(String sdncId) {
+        return aaiClientProvider.getAaiClient()
+                .get(EsrSystemInfoList.class,
+                        AAIUriFactory.createResourceUri(AAIObjectType.THIRDPARTY_SDNC_SYSTEM_INFO_LIST, sdncId))
+                .orElseGet(() -> {
+                    logger.debug("VNFM not found in AAI");
+                    return null;
+                });
+    }
+
+}