diff options
4 files changed, 368 insertions, 27 deletions
diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Properties.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Properties.java index a9675f5..dfe02f0 100644 --- a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Properties.java +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Properties.java @@ -4,6 +4,7 @@ * * org.onap.dcae * * ================================================================================ * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * Copyright (c) 2021 Nokia. 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. @@ -54,6 +55,8 @@ public class Properties { private String service_component_type; + private GetInput service_component_name_override; + private Map<String, Object> log_info; private String dns_name; diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/AppConfigService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/AppConfigService.java index 3db5ea0..da70511 100644 --- a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/AppConfigService.java +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/AppConfigService.java @@ -4,6 +4,7 @@ * * org.onap.dcae * * ================================================================================ * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * Copyright (c) 2021 Nokia. All rights reserved. * * ================================================================================ * * Modifications Copyright (c) 2021 Nokia * * ================================================================================ @@ -25,7 +26,6 @@ package org.onap.blueprintgenerator.service.common; -import org.onap.blueprintgenerator.constants.Constants; import org.onap.blueprintgenerator.model.common.Appconfig; import org.onap.blueprintgenerator.model.common.BaseStream; import org.onap.blueprintgenerator.model.common.GetInput; @@ -65,14 +65,12 @@ public class AppConfigService { * * @param inputs Inputs * @param onapComponentSpec Onap Component Specification - * @param override Parameter to Service Component Override * @param isDmaap Dmaap Argument * @return */ public Map<String, Object> createAppconfig( Map<String, LinkedHashMap<String, Object>> inputs, OnapComponentSpec onapComponentSpec, - String override, boolean isDmaap) { Map<String, Object> response = new HashMap<>(); @@ -118,13 +116,7 @@ public class AppConfigService { } } } - if (override != null) { - GetInput ov = new GetInput(); - ov.setBpInputName(Constants.SERVICE_COMPONENT_NAME_OVERRIDE); - parameters.put(Constants.SERVICE_COMPONENT_NAME_OVERRIDE, ov); - LinkedHashMap<String, Object> over = blueprintHelperService.createStringInput(override); - inputs.put(Constants.SERVICE_COMPONENT_NAME_OVERRIDE, over); - } + appconfig.setParams(parameters); response.put("appconfig", appconfig); diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PropertiesService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PropertiesService.java index 3c36cca..382cc2b 100644 --- a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PropertiesService.java +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PropertiesService.java @@ -4,6 +4,7 @@ * * org.onap.dcae * * ================================================================================ * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * Copyright (c) 2021 Nokia. 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. @@ -23,9 +24,15 @@ package org.onap.blueprintgenerator.service.common; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import org.onap.blueprintgenerator.constants.Constants; import org.onap.blueprintgenerator.model.common.Appconfig; import org.onap.blueprintgenerator.model.common.GetInput; +import org.onap.blueprintgenerator.model.common.Properties; import org.onap.blueprintgenerator.model.common.ResourceConfig; import org.onap.blueprintgenerator.model.componentspec.OnapAuxilary; import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; @@ -35,20 +42,12 @@ import org.onap.blueprintgenerator.model.dmaap.Streams; import org.onap.blueprintgenerator.model.dmaap.TlsInfo; import org.onap.blueprintgenerator.service.base.BlueprintHelperService; import org.onap.blueprintgenerator.service.dmaap.StreamsService; -import org.onap.blueprintgenerator.model.common.Properties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.HashMap; -import java.util.ArrayList; -import java.util.List; - /** * @author : Ravi Mantena - * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service to create Properties - * Node + * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service to create Properties Node */ @Service("onapPropertiesService") public class PropertiesService { @@ -71,9 +70,9 @@ public class PropertiesService { /** * Creates ONAP properties * - * @param inputs Inputs + * @param inputs Inputs * @param onapComponentSpec OnapComponentSpec - * @param override Override + * @param override Override * @return */ public Map<String, Object> createOnapProperties( @@ -88,7 +87,6 @@ public class PropertiesService { image.setBpInputName("image"); properties.setImage(image); - LinkedHashMap<String, Object> img = new LinkedHashMap<>(); inputs.put( "image", blueprintHelperService.createStringInput(onapComponentSpec.getArtifacts()[0].getUri())); @@ -97,7 +95,6 @@ public class PropertiesService { location.setBpInputName("location_id"); properties.setLocation_id(location); - LinkedHashMap<String, Object> locMap = new LinkedHashMap(); inputs.put("location_id", blueprintHelperService.createStringInput(Constants.EMPTY_VALUE)); properties.setLog_info(onapComponentSpec.getAuxilary().getLog_info()); @@ -115,7 +112,7 @@ public class PropertiesService { properties.setDocker_config(onapAuxilary); Map<String, Object> appConfigResponse = - appConfigService.createAppconfig(inputs, onapComponentSpec, override, false); + appConfigService.createAppconfig(inputs, onapComponentSpec, false); inputs = (Map<String, LinkedHashMap<String, Object>>) appConfigResponse.get("inputs"); properties.setApplication_config((Appconfig) appConfigResponse.get("appconfig")); @@ -133,6 +130,9 @@ public class PropertiesService { sType = sType.replace('.', '-'); properties.setService_component_type(sType); + inputs.put(Constants.SERVICE_COMPONENT_NAME_OVERRIDE, + addServiceComponentNameOverride(override, properties)); + Map<String, Object> tls_info = onapComponentSpec.getAuxilary().getTls_info(); if (tls_info != null) { addTlsInfo(onapComponentSpec, inputs, properties); @@ -156,9 +156,9 @@ public class PropertiesService { /** * Creates Dmaap properties * - * @param inputs Inputs + * @param inputs Inputs * @param onapComponentSpec OnapComponentSpec - * @param override Override + * @param override Override * @return */ public Map<String, Object> createDmaapProperties( @@ -191,6 +191,9 @@ public class PropertiesService { sType = sType.replace('.', '-'); properties.setService_component_type(sType); + inputs.put(Constants.SERVICE_COMPONENT_NAME_OVERRIDE, + addServiceComponentNameOverride(override, properties)); + Map<String, Object> tls_info = onapComponentSpec.getAuxilary().getTls_info(); if (tls_info != null) { addTlsInfo(onapComponentSpec, inputs, properties); @@ -212,7 +215,7 @@ public class PropertiesService { properties.setDocker_config(onapAuxilary); Map<String, Object> appConfigResponse = - appConfigService.createAppconfig(inputs, onapComponentSpec, override, true); + appConfigService.createAppconfig(inputs, onapComponentSpec, true); inputs = (Map<String, LinkedHashMap<String, Object>>) appConfigResponse.get("inputs"); properties.setApplication_config((Appconfig) appConfigResponse.get("appconfig")); @@ -310,6 +313,13 @@ public class PropertiesService { return response; } + private LinkedHashMap<String, Object> addServiceComponentNameOverride(String override, Properties properties) { + GetInput overrideGetInput = new GetInput(); + overrideGetInput.setBpInputName(Constants.SERVICE_COMPONENT_NAME_OVERRIDE); + properties.setService_component_name_override(overrideGetInput); + return blueprintHelperService.createStringInput(override != null ? override : ""); + } + private void addTlsInfo( OnapComponentSpec onapComponentSpec, Map<String, LinkedHashMap<String, Object>> inputs, diff --git a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/common/PropertiesServiceTest.java b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/common/PropertiesServiceTest.java new file mode 100644 index 0000000..a598315 --- /dev/null +++ b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/common/PropertiesServiceTest.java @@ -0,0 +1,336 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2021 Nokia 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. + * * 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.blueprintgenerator.service.common; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.model.common.GetInput; +import org.onap.blueprintgenerator.model.common.Properties; +import org.onap.blueprintgenerator.model.componentspec.OnapAuxilary; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; +import org.onap.blueprintgenerator.model.componentspec.common.Artifacts; +import org.onap.blueprintgenerator.model.componentspec.common.Publishes; +import org.onap.blueprintgenerator.model.componentspec.common.Self; +import org.onap.blueprintgenerator.model.componentspec.common.Streams; +import org.onap.blueprintgenerator.model.componentspec.common.Subscribes; +import org.onap.blueprintgenerator.model.componentspec.common.Volumes; +import org.onap.blueprintgenerator.model.dmaap.TlsInfo; +import org.onap.blueprintgenerator.service.base.BlueprintHelperService; +import org.onap.blueprintgenerator.service.dmaap.StreamsService; + +@RunWith(MockitoJUnitRunner.class) +public class PropertiesServiceTest { + + private static final String PROPERTIES = "properties"; + private static final String INPUTS = "inputs"; + + @InjectMocks + private PropertiesService propertiesService; + @Mock + private AppConfigService appConfigService; + @Mock + private ResourceConfigService resourceConfigService; + @Mock + private StreamsService streamsService; + @Mock + private BlueprintHelperService blueprintHelperService; + + private Map<String, ?> resourceConfigResponse; + + @Before + public void setup() { + resourceConfigResponse = Map.of(INPUTS, new LinkedHashMap<>()); + when(resourceConfigService.createResourceConfig(any(), eq(getSelf().getName()))) + .thenReturn((Map<String, Object>) resourceConfigResponse); + } + + @Test + public void shouldReturnInputsAndPropertiesForDmaap() { + //when + Map<String, Object> response = propertiesService + .createDmaapProperties(new HashMap<>(), getOnapComponentSpec(), ""); + + //then + assertTrue(response.get(PROPERTIES) instanceof Properties); + assertNotNull(response.get(INPUTS)); + assertEquals(resourceConfigResponse.get(INPUTS), response.get(INPUTS)); + assertEquals(getProperties("tag_version", false), response.get(PROPERTIES)); + + Properties actualProperties = (Properties) response.get(PROPERTIES); + assertNull(actualProperties.getStreams_subscribes()); + assertNull(actualProperties.getStreams_publishes()); + } + + @Test + public void shouldReturnInputsAndPropertiesForOnap() { + //given + when(appConfigService.createAppconfig(any(), eq(getOnapComponentSpec()), eq(false))) + .thenReturn((Map<String, Object>) resourceConfigResponse); + + //when + Map<String, Object> response = propertiesService + .createOnapProperties(new HashMap<>(), getOnapComponentSpec(), ""); + + //then + assertNotNull(response.get(PROPERTIES)); + assertTrue(response.get(PROPERTIES) instanceof Properties); + assertNotNull(response.get(INPUTS)); + assertEquals(resourceConfigResponse.get(INPUTS), response.get(INPUTS)); + assertEquals(getProperties("image", true), response.get(PROPERTIES)); + + Properties actualProperties = (Properties) response.get(PROPERTIES); + assertNull(actualProperties.getStreams_subscribes()); + assertNull(actualProperties.getStreams_publishes()); + } + + @Test + public void shouldSetStreamsMessageRoutesPublishesInProperties() { + //given + OnapComponentSpec onapComponentSpec = getOnapComponentSpecWithStreamsPublishes(); + Publishes publishes = onapComponentSpec.getStreams().getPublishes()[0]; + when(blueprintHelperService.isMessageRouterType(eq(publishes.getType()))).thenReturn(true); + when(streamsService.createStreams(any(), eq(publishes.getConfig_key() + Constants._TOPIC), + eq(publishes.getType()), + eq(publishes.getConfig_key()), + eq(publishes.getRoute()), + eq('p'))).thenReturn(getStreams()); + + //when + Map<String, Object> response = propertiesService + .createDmaapProperties(new HashMap<>(), onapComponentSpec, ""); + + //then + assertNotNull(response.get(PROPERTIES)); + assertTrue(response.get(PROPERTIES) instanceof Properties); + Properties actualProperties = (Properties) response.get(PROPERTIES); + assertNull(actualProperties.getStreams_subscribes()); + assertNotNull(actualProperties.getStreams_publishes()); + assertEquals(List.of(getDmaapStreams()), actualProperties.getStreams_publishes()); + } + + @Test + public void shouldSetStreamsDataRoutesPublishesInProperties() { + //given + OnapComponentSpec onapComponentSpec = getOnapComponentSpecWithStreamsPublishes(); + Publishes publishes = onapComponentSpec.getStreams().getPublishes()[0]; + when(blueprintHelperService.isDataRouterType(eq(publishes.getType()))).thenReturn(true); + when(streamsService.createStreams(any(), eq(publishes.getConfig_key() + Constants._FEED), + eq(publishes.getType()), + eq(publishes.getConfig_key()), + eq(publishes.getRoute()), + eq('p'))).thenReturn(getStreams()); + + //when + Map<String, Object> response = propertiesService + .createDmaapProperties(new HashMap<>(), onapComponentSpec, ""); + + //then + assertNotNull(response.get(PROPERTIES)); + assertTrue(response.get(PROPERTIES) instanceof Properties); + Properties actualProperties = (Properties) response.get(PROPERTIES); + assertNull(actualProperties.getStreams_subscribes()); + assertNotNull(actualProperties.getStreams_publishes()); + assertEquals(List.of(getDmaapStreams()), actualProperties.getStreams_publishes()); + } + + @Test + public void shouldSetStreamsDataRoutesSubscribesInProperties() { + //given + OnapComponentSpec onapComponentSpec = getOnapComponentSpecWithStreamsSubscribes(); + Subscribes subscribes = onapComponentSpec.getStreams().getSubscribes()[0]; + when(blueprintHelperService.isMessageRouterType(eq(subscribes.getType()))).thenReturn(true); + when(streamsService.createStreams(any(), eq(subscribes.getConfig_key() + Constants._TOPIC), + eq(subscribes.getType()), + eq(subscribes.getConfig_key()), + eq(subscribes.getRoute()), + eq('s'))).thenReturn(getStreams()); + + //when + Map<String, Object> response = propertiesService + .createDmaapProperties(new HashMap<>(), onapComponentSpec, ""); + + //then + assertNotNull(response.get(PROPERTIES)); + assertTrue(response.get(PROPERTIES) instanceof Properties); + Properties actualProperties = (Properties) response.get(PROPERTIES); + assertNull(actualProperties.getStreams_publishes()); + assertNotNull(actualProperties.getStreams_subscribes()); + assertEquals(List.of(getDmaapStreams()), actualProperties.getStreams_subscribes()); + } + + @Test + public void shouldSetStreamsMessageRoutesSubscribesInProperties() { + //given + OnapComponentSpec onapComponentSpec = getOnapComponentSpecWithStreamsSubscribes(); + Subscribes subscribes = onapComponentSpec.getStreams().getSubscribes()[0]; + when(blueprintHelperService.isDataRouterType(eq(subscribes.getType()))).thenReturn(true); + when(streamsService.createStreams(any(), eq(subscribes.getConfig_key() + Constants._FEED), + eq(subscribes.getType()), + eq(subscribes.getConfig_key()), + eq(subscribes.getRoute()), + eq('s'))).thenReturn(getStreams()); + + //when + Map<String, Object> response = propertiesService + .createDmaapProperties(new HashMap<>(), onapComponentSpec, ""); + + //then + assertNotNull(response.get(PROPERTIES)); + assertTrue(response.get(PROPERTIES) instanceof Properties); + Properties actualProperties = (Properties) response.get(PROPERTIES); + assertNull(actualProperties.getStreams_publishes()); + assertNotNull(actualProperties.getStreams_subscribes()); + assertEquals(List.of(getDmaapStreams()), actualProperties.getStreams_subscribes()); + } + + private OnapComponentSpec getOnapComponentSpecWithStreamsSubscribes() { + OnapComponentSpec onapComponentSpec = getOnapComponentSpec(); + Streams streams = new Streams(); + Subscribes subscribes = getSubscribes(); + streams.setSubscribes(new Subscribes[]{subscribes}); + onapComponentSpec.setStreams(streams); + return onapComponentSpec; + } + + private OnapComponentSpec getOnapComponentSpecWithStreamsPublishes() { + OnapComponentSpec onapComponentSpec = getOnapComponentSpec(); + Streams streams = new Streams(); + Publishes publishes1 = getPublishes(); + streams.setPublishes(new Publishes[]{publishes1}); + onapComponentSpec.setStreams(streams); + return onapComponentSpec; + } + + private HashMap<String, Object> getStreams() { + return new HashMap<>() {{ + put("streams", getDmaapStreams()); + }}; + } + + private org.onap.blueprintgenerator.model.dmaap.Streams getDmaapStreams() { + org.onap.blueprintgenerator.model.dmaap.Streams dmaapStreams = new org.onap.blueprintgenerator.model.dmaap.Streams(); + dmaapStreams.setName("testDmaapStreams"); + return dmaapStreams; + } + + private Publishes getPublishes() { + Publishes publishes = new Publishes(); + publishes.setConfig_key("test_config_key"); + publishes.setFormat("test_format"); + publishes.setRoute("test_route"); + publishes.setType("test_type"); + publishes.setVersion("test_version"); + return publishes; + } + + private Subscribes getSubscribes() { + Subscribes subscribes = new Subscribes(); + subscribes.setConfig_key("test_config_key_s"); + subscribes.setFormat("test_format_s"); + subscribes.setRoute("test_route_s"); + subscribes.setType("test_type_s"); + subscribes.setVersion("test_version_s"); + return subscribes; + } + + private Properties getProperties(String image, boolean alwaysPullImage) { + Properties expectedProperties = new Properties(); + expectedProperties.setDocker_config(getOnapAuxilary()); + expectedProperties.setImage(getGetInput(image)); + expectedProperties.setLocation_id(getGetInput("location_id")); + expectedProperties.setService_component_type("test-Name"); + expectedProperties.setService_component_name_override(getGetInput("service_component_name_override")); + expectedProperties.setLog_info(Collections.emptyMap()); + expectedProperties.setReplicas(getGetInput("replicas")); + expectedProperties.setTls_info(getTlsInfo()); + if (alwaysPullImage) { + expectedProperties.setAlways_pull_image(getGetInput("always_pull_image")); + } + return expectedProperties; + } + + private TlsInfo getTlsInfo() { + TlsInfo tlsInfo = new TlsInfo(); + tlsInfo.setUseTls(getGetInput("use_tls")); + return tlsInfo; + } + + private GetInput getGetInput(String location_id) { + GetInput location = new GetInput(); + location.setBpInputName(location_id); + return location; + } + + private OnapComponentSpec getOnapComponentSpec() { + OnapComponentSpec onapComponentSpec = new OnapComponentSpec(); + onapComponentSpec.setArtifacts(new Artifacts[]{getTestUriArtifact()}); + onapComponentSpec.setAuxilary(getOnapAuxilary()); + onapComponentSpec.setSelf(getSelf()); + return onapComponentSpec; + } + + private Self getSelf() { + Self self = new Self(); + self.setName("test.Name"); + return self; + } + + private Artifacts getTestUriArtifact() { + Artifacts artifacts = new Artifacts(); + artifacts.setUri("test://testUri"); + return artifacts; + } + + private OnapAuxilary getOnapAuxilary() { + OnapAuxilary onapAuxilary = new OnapAuxilary(); + onapAuxilary.setLog_info(Map.of()); + onapAuxilary.setTls_info(Map.of()); + onapAuxilary.setPorts(List.of("testPorts")); + onapAuxilary.setVolumes(new Volumes[]{getVolumes()}); + return onapAuxilary; + } + + private Volumes getVolumes() { + return new Volumes(); + } + +} |