diff options
7 files changed, 100 insertions, 23 deletions
diff --git a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PropertyOperator.java b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PropertyOperator.java index 2a73a27e..7ae27d2d 100644 --- a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PropertyOperator.java +++ b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PropertyOperator.java @@ -3,6 +3,7 @@ * ONAP : CCSDK.apps * ================================================================================ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2018 IBM. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,11 +25,13 @@ import static org.onap.ccsdk.apps.ms.neng.core.policy.PolicyReader.propertyOpera import java.lang.reflect.Method; import java.util.Map; +import java.util.logging.Logger; /** * Applies property operations while processing a policy. */ public class PropertyOperator { + private static Logger logger = Logger.getLogger(PropertyOperator.class.getName()); /** * Apply a property found in the policy. * @@ -117,7 +120,7 @@ public class PropertyOperator { } } } catch (Exception e) { - e.printStackTrace(); + logger.warning(e.getMessage()); throw e; } return postOp; diff --git a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceImpl.java b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceImpl.java index c5cabe51..347a2393 100644 --- a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceImpl.java +++ b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceImpl.java @@ -135,7 +135,7 @@ public class SpringServiceImpl implements SpringService { if (e instanceof NengException) { throw e; } else { - e.printStackTrace(); + log.warning(e.getMessage()); throw new Exception("Internal error occurred while processing the request"); } } @@ -149,6 +149,7 @@ public class SpringServiceImpl implements SpringService { try { return policyDetailsRepository.findPolicyResponseByName(policyName); } catch (Exception e) { + log.warning(e.getMessage()); return new PolicyDetails(); } } @@ -190,7 +191,7 @@ public class SpringServiceImpl implements SpringService { if (e instanceof NengException) { throw e; } else { - e.printStackTrace(); + log.warning(e.getMessage()); throw new Exception("Internal error occurred while processing the request"); } } diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/Elements.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/Elements.java index 20604634..5ad8561e 100644 --- a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/Elements.java +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/Elements.java @@ -40,6 +40,9 @@ public class Elements { @JsonProperty("allowed-range")
private List<AllowedRanges> allowedRanges;
+ @JsonProperty("shared-range")
+ private String sharedRange;
+
@JsonProperty("element-vlan-role")
String elementVlanRole;
@@ -76,7 +79,15 @@ public class Elements { this.allowedRanges = allowedRanges;
}
- public String getElementVlanRole() {
+ public String getSharedRange() {
+ return sharedRange;
+ }
+
+ public void setSharedRange(String sharedRange) {
+ this.sharedRange = sharedRange;
+ }
+
+ public String getElementVlanRole() {
return elementVlanRole;
}
@@ -84,12 +95,14 @@ public class Elements { this.elementVlanRole = elementVlanRole;
}
- @Override
- public String toString() {
- return "Elements [recycleVlantagRange=" + recycleVlantagRange + ", overwrite=" + overwrite + ", vlantagName="
- + vlantagName + ", allowedRanges=" + allowedRanges + ", elementVlanRole=" + elementVlanRole + "]";
- }
+ @Override
+ public String toString() {
+ return "Elements [recycleVlantagRange=" + recycleVlantagRange + ", overwrite=" + overwrite + ", vlantagName="
+ + vlantagName + ", allowedRanges=" + allowedRanges + ", sharedRange=" + sharedRange
+ + ", elementVlanRole=" + elementVlanRole + "]";
+ }
+
diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/service/VlantagApiServiceImpl.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/service/VlantagApiServiceImpl.java index 358241eb..93f8a21e 100644 --- a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/service/VlantagApiServiceImpl.java +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/service/VlantagApiServiceImpl.java @@ -165,6 +165,8 @@ public class VlantagApiServiceImpl implements VlantagApiService { rr.applicationId = "SDNC";
rr.rangeMaxOverride = -1;
rr.rangeMinOverride = -1;
+ if("TRUE".equalsIgnoreCase(element.getSharedRange()))
+ rr.resourceShareGroup = input.getScopeId();
List<Range> rangeList = new ArrayList<>();
for (AllowedRanges allowedRange : element.getAllowedRanges()) {
diff --git a/ms/vlantag-api/src/test/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/ElementsTest.java b/ms/vlantag-api/src/test/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/ElementsTest.java index 6d534ff0..c531adfa 100644 --- a/ms/vlantag-api/src/test/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/ElementsTest.java +++ b/ms/vlantag-api/src/test/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/ElementsTest.java @@ -48,6 +48,12 @@ public class ElementsTest { elements.setElementVlanRole("elementVlanRole"); assertEquals("elementVlanRole", elements.getElementVlanRole()); } + + @Test + public void testGetSetSharedRange() { + elements.setSharedRange("TRUE"); + assertEquals("TRUE", elements.getSharedRange()); + } @Test public void testToString() { diff --git a/ms/vlantag-api/src/test/java/org/onap/ccsdk/apps/ms/vlantagapi/core/service/TestVlantagApiServiceImpl.java b/ms/vlantag-api/src/test/java/org/onap/ccsdk/apps/ms/vlantagapi/core/service/TestVlantagApiServiceImpl.java index 18aa3024..b731b6a5 100644 --- a/ms/vlantag-api/src/test/java/org/onap/ccsdk/apps/ms/vlantagapi/core/service/TestVlantagApiServiceImpl.java +++ b/ms/vlantag-api/src/test/java/org/onap/ccsdk/apps/ms/vlantagapi/core/service/TestVlantagApiServiceImpl.java @@ -35,7 +35,6 @@ import org.mockito.junit.MockitoJUnitRunner; import org.onap.ccsdk.apps.ms.vlantagapi.core.exception.VlantagApiException;
import org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model.AllowedRanges;
import org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model.Elements;
-import org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model.PolicyEngineResponse;
import org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model.ResourceModel;
import org.onap.ccsdk.apps.ms.vlantagapi.core.model.AssignVlanTagRequest;
import org.onap.ccsdk.apps.ms.vlantagapi.core.model.AssignVlanTagRequestInput;
@@ -45,7 +44,7 @@ import org.onap.ccsdk.apps.ms.vlantagapi.core.model.UnassignVlanTagRequest; import org.onap.ccsdk.apps.ms.vlantagapi.core.model.UnassignVlanTagRequestInput;
import org.onap.ccsdk.apps.ms.vlantagapi.core.model.UnassignVlanTagResponse;
import org.onap.ccsdk.apps.ms.vlantagapi.core.service.VlantagApiServiceImpl;
-import org.onap.ccsdk.apps.ms.vlantagapi.extinf.pm.PolicyManagerClient;
+import org.onap.ccsdk.apps.ms.vlantagapi.util.MockPolicyClient;
import org.onap.ccsdk.apps.ms.vlantagapi.util.MockResourceAllocator;
import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceResponse;
import org.onap.ccsdk.sli.adaptors.util.str.StrUtil;
@@ -63,10 +62,10 @@ private static final Logger log = LoggerFactory.getLogger(TestVlantagApiServiceI VlantagApiServiceImpl serviceSpy;
@Spy
- private PolicyManagerClient policyEngineSpy;
-
- @Spy
protected static MockResourceAllocator mockRA2;
+
+ @Spy
+ protected static MockPolicyClient policyClient;
@Rule
@@ -75,13 +74,6 @@ private static final Logger log = LoggerFactory.getLogger(TestVlantagApiServiceI @Before
public void setup() throws Exception {
service = new VlantagApiServiceImpl();
-
- PolicyEngineResponse peResponse = new PolicyEngineResponse();
- peResponse.setConfig("{\"riskLevel\":\"4\",\"riskType\":\"test\",\"policyName\":\"Internet_VlanTag_1810_US_VPE\",\"service\":\"vlantagResourceModel\",\"guard\":\"False\",\"description\":\"Internet_VlanTag_1810_US_VPE\",\"templateVersion\":\"1607\",\"priority\":\"4\",\"version\":\"20180709\",\"content\":{\"policy-instance-name\":\"Internet_VlanTag_1810_US_VPE\",\"resource-models\":[{\"data-store\":\"FALSE\",\"elements\":[{\"allowed-range\":[{\"min\":\"3553\",\"max\":\"3562\"}],\"recycle-vlantag-range\":\"TRUE\",\"overwrite\":\"FALSE\",\"vlantag-name\":\"VPE-Cust\"}],\"scope\":\"SITE\",\"vlan-type\":\"vlan-id-outer\",\"resource-resolution-recipe\":\"#BSB# VPE-Cust #ESB#\",\"resource-vlan-role\":\"outer-tag\"},{\"data-store\":\"TRUE\",\"elements\":[{\"allowed-range\":[{\"min\":\"3503\",\"max\":\"3503\"}],\"element-vlan-role\":\"outer-tag\",\"recycle-vlantag-range\":\"TRUE\",\"overwrite\":\"FALSE\",\"vlantag-name\":\"VPE-Cust-Outer\"},{\"allowed-range\":[{\"min\":\"4001\",\"max\":\"4012\"}],\"element-vlan-role\":\"outer-tag\",\"recycle-vlantag-range\":\"TRUE\",\"overwrite\":\"FALSE\",\"vlantag-name\":\"VPE-Core1\"},{\"allowed-range\":[{\"min\":\"4001\",\"max\":\"4012\"}],\"element-vlan-role\":\"outer-tag\",\"recycle-vlantag-range\":\"TRUE\",\"overwrite\":\"FALSE\",\"vlantag-name\":\"VPE-Core2\"}],\"scope\":\"SITE\",\"vlan-type\":\"vlan-id-filter\",\"resource-resolution-recipe\":\"#BSB# VPE-Cust-Outer, VPE-Core1, VPE-Core2 #ESB#\"}]}}");
- PolicyEngineResponse[] peResponses = new PolicyEngineResponse[1];
- peResponses[0] = peResponse;
-
- Mockito.doReturn(peResponses).when(policyEngineSpy).getConfigUsingPost(any());
}
@Test
@@ -121,6 +113,26 @@ private static final Logger log = LoggerFactory.getLogger(TestVlantagApiServiceI }
@Test(expected = Test.None.class /* no exception expected */)
+ public void test_assign_sucess_002() throws Exception {
+
+ AssignVlanTagRequestInput input = new AssignVlanTagRequestInput();
+ input.setPolicyInstanceName("some-policy-instance");
+ input.setVlanType("vlan-id-filter");
+ input.setScopeId("some-scope-id");
+ input.setVlanTagKey("some-key");
+
+ AssignVlanTagRequest request = new AssignVlanTagRequest();
+ List<AssignVlanTagRequestInput> inputs = new ArrayList<>();
+ inputs.add(input);
+ request.setInput(inputs);
+
+ //PowerMockito.doReturn(mockStatus.Success).when(mockRA).reserve(any(), any(), any(), any());
+ AssignVlanTagResponse response = serviceSpy.assignVlanTag(request);
+
+ StrUtil.info(log, response);
+ }
+
+ @Test(expected = Test.None.class /* no exception expected */)
public void test_unassign_sucess_001() throws Exception {
UnassignVlanTagRequestInput input = new UnassignVlanTagRequestInput();
@@ -943,7 +955,7 @@ private static final Logger log = LoggerFactory.getLogger(TestVlantagApiServiceI @Test(expected = VlantagApiException.class)
public void testGetPolicyFromPDPFailure() throws Exception {
- Mockito.doThrow(new VlantagApiException()).when(policyEngineSpy).getConfigUsingPost(any());
- policyEngineSpy.getPolicyFromPDP("sonme_random_policy_name");
+ Mockito.doThrow(new VlantagApiException()).when(policyClient).getConfigUsingPost(any());
+ policyClient.getPolicyFromPDP("sonme_random_policy_name");
}
}
diff --git a/ms/vlantag-api/src/test/java/org/onap/ccsdk/apps/ms/vlantagapi/util/MockPolicyClient.java b/ms/vlantag-api/src/test/java/org/onap/ccsdk/apps/ms/vlantagapi/util/MockPolicyClient.java new file mode 100644 index 00000000..bd95b2f9 --- /dev/null +++ b/ms/vlantag-api/src/test/java/org/onap/ccsdk/apps/ms/vlantagapi/util/MockPolicyClient.java @@ -0,0 +1,40 @@ +/*******************************************************************************
+ * Copyright © 2017-2018 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.
+ * 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.
+ ******************************************************************************/
+
+package org.onap.ccsdk.apps.ms.vlantagapi.util;
+
+import org.onap.ccsdk.apps.ms.vlantagapi.core.exception.VlantagApiException;
+import org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model.PolicyEngineResponse;
+import org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model.RequestObject;
+import org.onap.ccsdk.apps.ms.vlantagapi.extinf.pm.PolicyManagerClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MockPolicyClient extends PolicyManagerClient{
+ protected static final Logger logger = LoggerFactory.getLogger(MockPolicyClient.class);
+
+
+
+ public PolicyEngineResponse[] getConfigUsingPost(RequestObject requestObject) throws VlantagApiException {
+
+ PolicyEngineResponse peResponse = new PolicyEngineResponse();
+ peResponse.setConfig("{\"riskLevel\":\"4\",\"riskType\":\"test\",\"policyName\":\"Internet_VlanTag_1810_US_VPE\",\"service\":\"vlantagResourceModel\",\"guard\":\"False\",\"description\":\"Internet_VlanTag_1810_US_VPE\",\"templateVersion\":\"1607\",\"priority\":\"4\",\"version\":\"20180709\",\"content\":{\"policy-instance-name\":\"Internet_VlanTag_1810_US_VPE\",\"resource-models\":[{\"data-store\":\"FALSE\",\"elements\":[{\"allowed-range\":[{\"min\":\"3553\",\"max\":\"3562\"}],\"recycle-vlantag-range\":\"TRUE\",\"overwrite\":\"FALSE\",\"vlantag-name\":\"VPE-Cust\"}],\"scope\":\"SITE\",\"vlan-type\":\"vlan-id-outer\",\"resource-resolution-recipe\":\"#BSB# VPE-Cust #ESB#\",\"resource-vlan-role\":\"outer-tag\"},{\"data-store\":\"TRUE\",\"elements\":[{\"allowed-range\":[{\"min\":\"3503\",\"max\":\"3503\"}],\"shared-range\":\"TRUE\",\"element-vlan-role\":\"outer-tag\",\"recycle-vlantag-range\":\"TRUE\",\"overwrite\":\"FALSE\",\"vlantag-name\":\"VPE-Cust-Outer\"},{\"allowed-range\":[{\"min\":\"4001\",\"max\":\"4012\"}],\"element-vlan-role\":\"outer-tag\",\"recycle-vlantag-range\":\"TRUE\",\"overwrite\":\"FALSE\",\"vlantag-name\":\"VPE-Core1\"},{\"allowed-range\":[{\"min\":\"4001\",\"max\":\"4012\"}],\"element-vlan-role\":\"outer-tag\",\"recycle-vlantag-range\":\"TRUE\",\"overwrite\":\"FALSE\",\"vlantag-name\":\"VPE-Core2\"}],\"scope\":\"SITE\",\"vlan-type\":\"vlan-id-filter\",\"resource-resolution-recipe\":\"#BSB# VPE-Cust-Outer, VPE-Core1, VPE-Core2 #ESB#\"}]}}");
+ PolicyEngineResponse[] peResponses = new PolicyEngineResponse[1];
+ peResponses[0] = peResponse;
+
+ return peResponses;
+ }
+}
|