diff options
author | 2021-02-05 15:16:38 -0500 | |
---|---|---|
committer | 2021-02-05 15:17:25 -0500 | |
commit | 6d5c367c38a83608f5c0639692e7f7eba772a88f (patch) | |
tree | 49eee3b67d80b1a15c1e11276d967acbab95ee31 /controlloop/common/controller-usecases/src/main/java/org/onap | |
parent | 7ec9d2ca8f1bb83eb3f9ab30a2f14f3b475df6cf (diff) |
Give better messages than NPE for missing data
When data is not available to actor operations, an NPE is generally
thrown. Modified the code to provide more info about what is missing
than simply NPE.
Issue-ID: POLICY-2913
Change-Id: Ic56376ef5fdd0f2e46c2996405fff9aafa3692b9
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'controlloop/common/controller-usecases/src/main/java/org/onap')
-rw-r--r-- | controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/step/Step2.java | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/step/Step2.java b/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/step/Step2.java index ca7b63f69..dbdc6b9fa 100644 --- a/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/step/Step2.java +++ b/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/step/Step2.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 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. @@ -285,16 +285,17 @@ public class Step2 extends Step { protected CloudRegion getCloudRegion() { AaiCqResponse aaicq = getCustomQueryData(); - return aaicq.getDefaultCloudRegion(); + return verifyNotNull("default cloud region in A&AI response", aaicq.getDefaultCloudRegion()); } protected Tenant getTenant() { AaiCqResponse aaicq = getCustomQueryData(); - return aaicq.getDefaultTenant(); + return verifyNotNull("default tenant in A&AI response", aaicq.getDefaultTenant()); } protected StandardCoderObject getPnf() { - return stepContext.getProperty(AaiGetPnfOperation.getKey(getTargetEntity())); + String target = getTargetEntity(); + return verifyNotNull("PNF for " + target, stepContext.getProperty(AaiGetPnfOperation.getKey(target))); } protected GenericVnf getResourceVnf() { @@ -305,23 +306,25 @@ public class Step2 extends Step { verifyNotNull("Target resource ID", resourceId); AaiCqResponse aaicq = getCustomQueryData(); - return aaicq.getGenericVnfByModelInvariantId(resourceId); + return verifyNotNull("VNF for " + resourceId, aaicq.getGenericVnfByModelInvariantId(resourceId)); } protected ServiceInstance getService() { AaiCqResponse aaicq = getCustomQueryData(); - return aaicq.getServiceInstance(); + return verifyNotNull("service instance in A&AI response", aaicq.getServiceInstance()); } protected ModelVer getServiceModel() { AaiCqResponse aaicq = getCustomQueryData(); - ServiceInstance service = aaicq.getServiceInstance(); - return aaicq.getModelVerByVersionId(service.getModelVersionId()); + ServiceInstance service = getService(); + String modelVersionId = verifyNotNull("service model version ID in A&AI response", service.getModelVersionId()); + return verifyNotNull("model version for service in A&AI response", + aaicq.getModelVerByVersionId(modelVersionId)); } protected Vserver getVServer() { AaiCqResponse aaicq = getCustomQueryData(); - return aaicq.getVserver(); + return verifyNotNull("vserver in A&AI response", aaicq.getVserver()); } /** @@ -329,7 +332,7 @@ public class Step2 extends Step { * within the step's context. */ protected String getTargetEntity() { - return stepContext.getProperty(OperationProperties.AAI_TARGET_ENTITY); + return verifyNotNull("A&AI target entity", stepContext.getProperty(OperationProperties.AAI_TARGET_ENTITY)); } protected GenericVnf getVnf() { @@ -340,13 +343,17 @@ public class Step2 extends Step { verifyNotNull(TARGET_MODEL_INVARIANT_ID, modelInvariantId); AaiCqResponse aaicq = getCustomQueryData(); - return aaicq.getGenericVnfByVfModuleModelInvariantId(modelInvariantId); + return verifyNotNull("generic VNF in A&AI response for " + modelInvariantId, + aaicq.getGenericVnfByVfModuleModelInvariantId(modelInvariantId)); } protected ModelVer getVnfModel() { GenericVnf vnf = getVnf(); + String modelVersionId = + verifyNotNull("model version ID for generic VNF in A&AI response", vnf.getModelVersionId()); AaiCqResponse aaicq = getCustomQueryData(); - return aaicq.getModelVerByVersionId(vnf.getModelVersionId()); + return verifyNotNull("model version for generic VNF in A&AI response", + aaicq.getModelVerByVersionId(modelVersionId)); } protected String getVserverLink() { @@ -401,7 +408,7 @@ public class Step2 extends Step { protected GenericVnf getDefaultGenericVnf() { AaiCqResponse aaicq = getCustomQueryData(); - return aaicq.getDefaultGenericVnf(); + return verifyNotNull("generic VNF in A&AI response", aaicq.getDefaultGenericVnf()); } protected AaiCqResponse getCustomQueryData() { @@ -420,11 +427,13 @@ public class Step2 extends Step { stepContext.setProperty(OperationProperties.DATA_VF_COUNT, vfcount); } - protected void verifyNotNull(String propName, Object value) { + protected <T> T verifyNotNull(String propName, T value) { if (value == null) { throw new IllegalArgumentException( "missing " + propName + " for " + getActorName() + "." + getOperationName()); } + + return value; } protected static String stripPrefix(String resourceLink, int ncomponents) { |