summaryrefslogtreecommitdiffstats
path: root/appc-dg/appc-dg-shared/appc-dg-aai
diff options
context:
space:
mode:
authorDunietz, Irwin <id1681@att.com>2020-01-16 15:13:14 -0500
committerTakamune Cho <takamune.cho@att.com>2020-01-29 19:44:48 +0000
commitb5fe8a69e90b950c07dc11af481eab7e9bab52c6 (patch)
tree3da81ce60554e65b93776b9aea647f3c6d8679ab /appc-dg/appc-dg-shared/appc-dg-aai
parent9b32cb60360a2a2973c621053510718de0072111 (diff)
Change code in appc dispatcher for new LCMs in R6
Also introduce some minor improvements to robustness, efficiency, & formatting. Issue-ID: APPC-1789 Signed-off-by: Dunietz, Irwin <id1681@att.com> Change-Id: I82d970c2f7cde6c8dab1222af86ea70ce93b7e50
Diffstat (limited to 'appc-dg/appc-dg-shared/appc-dg-aai')
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/onap/appc/dg/aai/impl/AAIPluginImpl.java83
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-aai/src/test/java/org/onap/appc/dg/aai/impl/AAIPluginImplTest.java26
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-aai/src/test/java/org/onap/appc/dg/aai/impl/TestConstants.java30
3 files changed, 70 insertions, 69 deletions
diff --git a/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/onap/appc/dg/aai/impl/AAIPluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/onap/appc/dg/aai/impl/AAIPluginImpl.java
index 3044236b2..a98b01ddb 100644
--- a/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/onap/appc/dg/aai/impl/AAIPluginImpl.java
+++ b/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/onap/appc/dg/aai/impl/AAIPluginImpl.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* ================================================================================
@@ -11,15 +11,14 @@
* 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=========================================================
*/
@@ -42,11 +41,11 @@ import org.onap.appc.domainmodel.Vnfc;
import org.onap.appc.domainmodel.Vserver;
import org.onap.appc.exceptions.APPCException;
import org.onap.appc.i18n.Msg;
-import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
-import org.onap.ccsdk.sli.adaptors.aai.AAIService;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
+import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
+import org.onap.ccsdk.sli.adaptors.aai.AAIService;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
@@ -117,8 +116,8 @@ public class AAIPluginImpl implements AAIPlugin {
ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg);
throw new APPCException(msg);
}
- String msg = EELFResourceManager
- .format(Msg.SUCCESS_EVENT_MESSAGE, "PostGenericVnfData", STR_VNF_ID + vnfId);
+ String msg =
+ EELFResourceManager.format(Msg.SUCCESS_EVENT_MESSAGE, "PostGenericVnfData", STR_VNF_ID + vnfId);
ctx.setAttribute(org.onap.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE, msg);
} catch (SvcLogicException e) {
@@ -136,8 +135,8 @@ public class AAIPluginImpl implements AAIPlugin {
String key = "vnf-id = '" + vnfId + "'";
try {
- SvcLogicResource.QueryStatus response = aaiClient
- .query(PARAM_GENERIC_VNF, false, null, key, prefix, null, ctx);
+ SvcLogicResource.QueryStatus response =
+ aaiClient.query(PARAM_GENERIC_VNF, false, null, key, prefix, null, ctx);
if (SvcLogicResource.QueryStatus.NOT_FOUND.equals(response)) {
String msg = EELFResourceManager.format(Msg.VNF_NOT_FOUND, vnfId);
ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg);
@@ -157,7 +156,7 @@ public class AAIPluginImpl implements AAIPlugin {
}
ctx.setAttribute(Constants.IS_RELEASE_ENTITLEMENT_REQUIRE,
- Boolean.toString(!aaiEntitlementPoolUuid.isEmpty()));
+ Boolean.toString(!aaiEntitlementPoolUuid.isEmpty()));
ctx.setAttribute(Constants.IS_RELEASE_LICENSE_REQUIRE, Boolean.toString(!aaiLicenseKeyGroupUuid.isEmpty()));
String msg = EELFResourceManager.format(Msg.SUCCESS_EVENT_MESSAGE, "GetGenericVnfData", STR_VNF_ID + vnfId);
ctx.setAttribute(org.onap.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE, msg);
@@ -213,8 +212,9 @@ public class AAIPluginImpl implements AAIPlugin {
Vnfc newVnfc = createVnfc(vnfcName, vnfcType);
if (vnfcSet.contains(newVnfc)) {
- Vnfc vnfcFromSet = vnfcSet.stream().filter(vnfc -> vnfc.equals(newVnfc))
- .collect(Collectors.toList()).get(0);
+ Vnfc vnfcFromSet =
+ vnfcSet.stream().filter(vnfc -> vnfc.equals(newVnfc))
+ .collect(Collectors.toList()).get(0);
vnfcFromSet.addVserver(vm);
vm.setVnfc(vnfcFromSet);
} else {
@@ -232,8 +232,8 @@ public class AAIPluginImpl implements AAIPlugin {
ctx.setAttribute("getVnfHierarchy_result", "FAILURE");
String msg = EELFResourceManager.format(Msg.AAI_QUERY_FAILED, vnfId);
ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg);
- logger.error("Failed in getVnfHierarchy, Error retrieving VNF details. Error message: " + ctx
- .getAttribute("getResource_result"), e);
+ logger.error("Failed in getVnfHierarchy, Error retrieving VNF details. Error message: "
+ + ctx.getAttribute("getResource_result"), e);
logger.warn("Incorrect or Incomplete VNF Hierarchy");
throw new APPCException("Error Retrieving VNF hierarchy");
}
@@ -291,22 +291,22 @@ public class AAIPluginImpl implements AAIPlugin {
String resourceType = "vnfc";
SvcLogicContext vnfContext = readResource(query, prefix, resourceType);
String[] additionalProperties = new String[]{PROPERTY_VNFC_TYPE, PROPERTY_VNFC_NAME,
- PROPERTY_VNFC_FUNC_CODE, PROPERTY_IN_MAINT, PROPERTY_PROV_STATUS,
- PROPERTY_LOOP_DISABLED, PROPERTY_ORCHESTRATION_STATUS, PROPERTY_RESOURCE_VERSION};
+ PROPERTY_VNFC_FUNC_CODE, PROPERTY_IN_MAINT, PROPERTY_PROV_STATUS,
+ PROPERTY_LOOP_DISABLED, PROPERTY_ORCHESTRATION_STATUS, PROPERTY_RESOURCE_VERSION};
return readRelationDataAndProperties(prefix, vnfContext, additionalProperties);
}
protected AAIQueryResult readVM(String vmId, String tenantId, String cloudOwner, String cloudRegionId)
throws AAIQueryException {
String query = "vserver.vserver-id = '" + vmId + "' AND tenant.tenant_id = '" + tenantId
- + "' AND cloud-region.cloud-owner = '"
- + cloudOwner + "' AND cloud-region.cloud-region-id = '" + cloudRegionId + "'";
+ + "' AND cloud-region.cloud-owner = '" + cloudOwner
+ + "' AND cloud-region.cloud-region-id = '" + cloudRegionId + "'";
String prefix = "VM";
String resourceType = "vserver";
SvcLogicContext vnfContext = readResource(query, prefix, resourceType);
String[] additionalProperties = new String[]{PROPERTY_VSERVER_ID, PROPERTY_VSERVER_SLINK,
- PROPERTY_VSERVER_NAME, PROPERTY_IN_MAINT, PROPERTY_PROV_STATUS, PROPERTY_LOOP_DISABLED,
- PROPERTY_VSERVER_NAME_2, PROPERTY_RESOURCE_VERSION,};
+ PROPERTY_VSERVER_NAME, PROPERTY_IN_MAINT, PROPERTY_PROV_STATUS, PROPERTY_LOOP_DISABLED,
+ PROPERTY_VSERVER_NAME_2, PROPERTY_RESOURCE_VERSION,};
return readRelationDataAndProperties(prefix, vnfContext, additionalProperties);
}
@@ -317,18 +317,19 @@ public class AAIPluginImpl implements AAIPlugin {
SvcLogicContext vnfContext = readResource(query, prefix, PARAM_GENERIC_VNF);
String[] additionalProperties = new String[]{PROPERTY_VNF_TYPE, PROPERTY_VNF_NEM,
- PROPERTY_IN_MAINT, PROPERTY_PROV_STATUS, PROPERTY_HEAT_STACK_ID,
- PROPERTY_LOOP_DISABLED, PROPERTY_ORCHESTRATION_STATUS, PROPERTY_RESOURCE_VERSION, Constants.AAI_VNF_MODEL_VERSION_ID};
+ PROPERTY_IN_MAINT, PROPERTY_PROV_STATUS, PROPERTY_HEAT_STACK_ID,
+ PROPERTY_LOOP_DISABLED, PROPERTY_ORCHESTRATION_STATUS, PROPERTY_RESOURCE_VERSION,
+ Constants.AAI_VNF_MODEL_VERSION_ID};
return readRelationDataAndProperties(prefix, vnfContext, additionalProperties);
}
private AAIQueryResult readRelationDataAndProperties(String prefix, SvcLogicContext context,
- String[] additionalProperties) {
+ String[] additionalProperties) {
AAIQueryResult result = new AAIQueryResult();
if (context != null && context.getAttribute(prefix + ".relationship-list.relationship_length") != null) {
- Integer relationsCount = Integer.parseInt(context.getAttribute(
- prefix + ".relationship-list.relationship_length"));
+ Integer relationsCount =
+ Integer.parseInt(context.getAttribute(prefix + ".relationship-list.relationship_length"));
for (int i = 0; i < relationsCount; i++) {
String rsKey = prefix + ".relationship-list.relationship[" + i + "]";
Relationship relationShip = new Relationship();
@@ -360,7 +361,7 @@ public class AAIPluginImpl implements AAIPlugin {
}
} else {
logger.error("Relationship-list not present in the SvcLogicContext attributes set."
- + (context == null ? "" : "Attribute KeySet = " + context.getAttributeKeySet()));
+ + (context == null ? "" : " Attribute KeySet = " + context.getAttributeKeySet()));
}
if (context != null) {
@@ -374,8 +375,8 @@ public class AAIPluginImpl implements AAIPlugin {
protected SvcLogicContext readResource(String query, String prefix, String resourceType) throws AAIQueryException {
SvcLogicContext resourceContext = new SvcLogicContext();
try {
- SvcLogicResource.QueryStatus response = aaiClient
- .query(resourceType, false, null, query, prefix, null, resourceContext);
+ SvcLogicResource.QueryStatus response =
+ aaiClient.query(resourceType, false, null, query, prefix, null, resourceContext);
logger.info(STR_AAI_RESPONSE + response.toString());
if (!SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
throw new AAIQueryException("Error Retrieving VNF hierarchy from A&AI");
@@ -393,20 +394,18 @@ public class AAIPluginImpl implements AAIPlugin {
String ctxPrefix = params.get("prefix");
String resourceKey = params.get(PARAM_RESOURCE_KEY);
if (logger.isDebugEnabled()) {
- logger.debug("inside getResorce");
- logger.debug("Retrieving " + resourceType + " details from A&AI for Key : " + resourceKey);
+ logger.debug("inside getResource");
+ logger.debug("Retrieving " + resourceType + " details from A&AI for Key: " + resourceKey);
}
try {
SvcLogicResource.QueryStatus response =
- aaiClient.query(resourceType, false, null, resourceKey, ctxPrefix, null, ctx);
+ aaiClient.query(resourceType, false, null, resourceKey, ctxPrefix, null, ctx);
logger.info(STR_AAI_RESPONSE + response.toString());
ctx.setAttribute("getResource_result", response.toString());
} catch (SvcLogicException e) {
logger.error(EELFResourceManager.format(Msg.AAI_GET_DATA_FAILED, resourceKey), e);
}
- if (logger.isDebugEnabled()) {
- logger.debug("exiting getResource======");
- }
+ logger.debug("exiting getResource======");
}
@Override
@@ -418,8 +417,8 @@ public class AAIPluginImpl implements AAIPlugin {
String attributeValue = params.get("attributeValue");
if (logger.isDebugEnabled()) {
logger.debug("inside postResource");
- logger.debug("Updating " + resourceType + " details in A&AI for Key : " + resourceKey);
- logger.debug("Updating " + attributeName + " to : " + attributeValue);
+ logger.debug("Updating " + resourceType + " details in A&AI for Key: " + resourceKey);
+ logger.debug("Updating " + attributeName + " to: " + attributeValue);
}
Map<String, String> data = new HashMap<>();
data.put(attributeName, attributeValue);
@@ -431,9 +430,7 @@ public class AAIPluginImpl implements AAIPlugin {
} catch (SvcLogicException e) {
logger.error(EELFResourceManager.format(Msg.AAI_UPDATE_FAILED, resourceKey, attributeValue), e);
}
- if (logger.isDebugEnabled()) {
- logger.debug("exiting postResource======");
- }
+ logger.debug("exiting postResource======");
}
@Override
@@ -443,7 +440,7 @@ public class AAIPluginImpl implements AAIPlugin {
if (logger.isDebugEnabled()) {
logger.debug("inside deleteResource");
- logger.debug("Deleting " + resourceType + " details From A&AI for Key : " + resourceKey);
+ logger.debug("Deleting " + resourceType + " details from A&AI for Key: " + resourceKey);
}
try {
SvcLogicResource.QueryStatus response = aaiClient.delete(resourceType, resourceKey, ctx);
@@ -452,8 +449,6 @@ public class AAIPluginImpl implements AAIPlugin {
} catch (SvcLogicException e) {
logger.error(EELFResourceManager.format(Msg.AAI_DELETE_FAILED, resourceKey), e);
}
- if (logger.isDebugEnabled()) {
- logger.debug("exiting deleteResource======");
- }
+ logger.debug("exiting deleteResource======");
}
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-aai/src/test/java/org/onap/appc/dg/aai/impl/AAIPluginImplTest.java b/appc-dg/appc-dg-shared/appc-dg-aai/src/test/java/org/onap/appc/dg/aai/impl/AAIPluginImplTest.java
index d89bd4730..12dde3141 100644
--- a/appc-dg/appc-dg-shared/appc-dg-aai/src/test/java/org/onap/appc/dg/aai/impl/AAIPluginImplTest.java
+++ b/appc-dg/appc-dg-shared/appc-dg-aai/src/test/java/org/onap/appc/dg/aai/impl/AAIPluginImplTest.java
@@ -3,6 +3,8 @@
* ONAP : APPC
* ================================================================================
* Copyright (C) 2018 Ericsson
+ * ================================================================================
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -111,8 +113,8 @@ public class AAIPluginImplTest {
AAIPluginImpl impl = new AAIPluginImpl();
impl.initialize();
impl.postGenericVnfData(params, ctx);
- Assert.assertThat(ctx.getAttribute(org.onap.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE), CoreMatchers.containsString(
- "Operation PostGenericVnfData succeed for VNF ID null"));
+ Assert.assertThat(ctx.getAttribute(org.onap.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE),
+ CoreMatchers.containsString("Operation PostGenericVnfData succeed for VNF ID null"));
}
@Test
@@ -162,14 +164,15 @@ public class AAIPluginImplTest {
AAIPluginImpl impl = new AAIPluginImpl();
impl.initialize();
impl.getGenericVnfData(params, ctx);
- Assert.assertThat(ctx.getAttribute(org.onap.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE), CoreMatchers.containsString(
- "Operation GetGenericVnfData succeed for VNF ID null"));
+ Assert.assertThat(ctx.getAttribute(org.onap.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE),
+ CoreMatchers.containsString("Operation GetGenericVnfData succeed for VNF ID null"));
}
@Test
public void testGetGenericVnfDataFailureThrownExeption() throws APPCException, SvcLogicException {
- Mockito.doThrow(new SvcLogicException()).when(aaiClient).query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
- Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(SvcLogicContext.class));
+ Mockito.doThrow(new SvcLogicException()).when(aaiClient).query(Mockito.anyString(), Mockito.anyBoolean(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
+ Mockito.any(SvcLogicContext.class));
ctx = new SvcLogicContext();
AAIPluginImpl impl = new AAIPluginImpl();
impl.initialize();
@@ -194,8 +197,9 @@ public class AAIPluginImplTest {
@Test
public void testGetVnfHierarchyAaiExceptionFlow2() throws APPCException, SvcLogicException {
- Mockito.doThrow(new SvcLogicException()).when(aaiClient).query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
- Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(SvcLogicContext.class));
+ Mockito.doThrow(new SvcLogicException()).when(aaiClient).query(Mockito.anyString(), Mockito.anyBoolean(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
+ Mockito.any(SvcLogicContext.class));
ctx = new SvcLogicContext();
params.put(Constants.RESOURCEKEY, "TEST_RESOURCE_KEY");
AAIPluginImpl impl = new AAIPluginImpl();
@@ -268,7 +272,7 @@ public class AAIPluginImplTest {
AAIPluginImpl impl = new AAIPluginImpl();
impl.initialize();
impl.getResource(params, ctx);
- Assert.assertEquals("SUCCESS",ctx.getAttribute("getResource_result"));
+ Assert.assertEquals("SUCCESS", ctx.getAttribute("getResource_result"));
}
@Test
@@ -281,7 +285,7 @@ public class AAIPluginImplTest {
AAIPluginImpl impl = new AAIPluginImpl();
impl.initialize();
impl.postResource(params, ctx);
- Assert.assertEquals("SUCCESS",ctx.getAttribute("postResource_result"));
+ Assert.assertEquals("SUCCESS", ctx.getAttribute("postResource_result"));
}
@Test
@@ -294,6 +298,6 @@ public class AAIPluginImplTest {
AAIPluginImpl impl = new AAIPluginImpl();
impl.initialize();
impl.deleteResource(params, ctx);
- Assert.assertEquals("SUCCESS",ctx.getAttribute("deleteResource_result"));
+ Assert.assertEquals("SUCCESS", ctx.getAttribute("deleteResource_result"));
}
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-aai/src/test/java/org/onap/appc/dg/aai/impl/TestConstants.java b/appc-dg/appc-dg-shared/appc-dg-aai/src/test/java/org/onap/appc/dg/aai/impl/TestConstants.java
index ec562f0a0..1d269a985 100644
--- a/appc-dg/appc-dg-shared/appc-dg-aai/src/test/java/org/onap/appc/dg/aai/impl/TestConstants.java
+++ b/appc-dg/appc-dg-shared/appc-dg-aai/src/test/java/org/onap/appc/dg/aai/impl/TestConstants.java
@@ -5,6 +5,8 @@
* Copyright 2018 TechMahindra
* ================================================================================
* Modifications Copyright (C) 2019 Ericsson
+* ================================================================================
+* Modifications Copyright (C) 2019 AT&T Intellectual Property
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,21 +29,21 @@ import org.junit.Test;
import org.onap.appc.dg.aai.impl.Constants.SDC_ARTIFACTS_FIELDS;
public class TestConstants {
- private SDC_ARTIFACTS_FIELDS c=SDC_ARTIFACTS_FIELDS.SERVICE_NAME;
+ private SDC_ARTIFACTS_FIELDS c = SDC_ARTIFACTS_FIELDS.SERVICE_NAME;
- @Test
- public void testConstants() {
- Assert.assertEquals("sdnctl",Constants.NETCONF_SCHEMA);
- }
+ @Test
+ public void testConstants() {
+ Assert.assertEquals("sdnctl", Constants.NETCONF_SCHEMA);
+ }
- @Test
- public void testName() {
- Assert.assertEquals("SERVICE_NAME",c.name());
- }
+ @Test
+ public void testName() {
+ Assert.assertEquals("SERVICE_NAME", c.name());
+ }
- @Test
- public void testEqual() {
- Assert.assertTrue(c.equals(SDC_ARTIFACTS_FIELDS.SERVICE_NAME));
- Assert.assertFalse(c.equals(null));
- }
+ @Test
+ public void testEqual() {
+ Assert.assertTrue(c.equals(SDC_ARTIFACTS_FIELDS.SERVICE_NAME));
+ Assert.assertFalse(c.equals(null));
+ }
}