diff options
Diffstat (limited to 'src')
8 files changed, 188 insertions, 50 deletions
diff --git a/src/main/java/org/onap/clamp/clds/config/spring/CldsSdcControllerConfiguration.java b/src/main/java/org/onap/clamp/clds/config/spring/CldsSdcControllerConfiguration.java index 1fb86c0ce..3f1403f1e 100644 --- a/src/main/java/org/onap/clamp/clds/config/spring/CldsSdcControllerConfiguration.java +++ b/src/main/java/org/onap/clamp/clds/config/spring/CldsSdcControllerConfiguration.java @@ -17,6 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END============================================ + * * Modifications copyright (c) 2019 Nokia * =================================================================== * */ @@ -92,11 +93,6 @@ public class CldsSdcControllerConfiguration { }); } - @Bean(name = "csarInstaller") - public CsarInstaller getCsarInstaller() { - return new CsarInstallerImpl(); - } - @Bean(name = "sdcControllersConfiguration") public SdcControllersConfiguration getSdcControllersConfiguration() { return new SdcControllersConfiguration(); diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java index 17739963e..a4ae14d00 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java @@ -17,6 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END============================================ + * Modifications copyright (c) 2019 Nokia * =================================================================== * */ @@ -56,6 +57,7 @@ import org.onap.clamp.clds.util.drawing.SvgFacade; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext; +import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import org.yaml.snakeyaml.Yaml; @@ -64,6 +66,7 @@ import org.yaml.snakeyaml.Yaml; * There is no state kept by the bean. It's used to deploy the csar/notification * received from SDC in DB. */ +@Component public class CsarInstallerImpl implements CsarInstaller { private static final EELFLogger logger = EELFManager.getInstance().getLogger(CsarInstallerImpl.class); @@ -78,20 +81,26 @@ public class CsarInstallerImpl implements CsarInstaller { */ @Value("${clamp.config.sdc.blueprint.parser.mapping:'classpath:/clds/blueprint-parser-mapping.json'}") protected String blueprintMappingFile; - @Autowired protected ApplicationContext appContext; - @Autowired private CldsDao cldsDao; - @Autowired CldsTemplateService cldsTemplateService; - @Autowired CldsService cldsService; - @Autowired DcaeInventoryServices dcaeInventoryService; - @Autowired private XslTransformer cldsBpmnTransformer; @Autowired + public CsarInstallerImpl(ApplicationContext appContext, + CldsDao cldsDao, CldsTemplateService cldsTemplateService, CldsService cldsService, + DcaeInventoryServices dcaeInventoryService, XslTransformer cldsBpmnTransformer) { + this.appContext = appContext; + this.cldsDao = cldsDao; + this.cldsTemplateService = cldsTemplateService; + this.cldsService = cldsService; + this.dcaeInventoryService = dcaeInventoryService; + this.cldsBpmnTransformer = cldsBpmnTransformer; + } + + @Autowired private BlueprintParser blueprintParser; @Autowired @@ -155,16 +164,7 @@ public class CsarInstallerImpl implements CsarInstaller { } } - private void createPolicyModel(CsarHandler csar) throws PolicyModelException { - try{ - Optional<String> policyModelYaml = csar.getPolicyModelYaml(); - // save policy model into the database - } catch (IOException e) { - throw new PolicyModelException("TransformerException when decoding the YamlText", e); - } - } - - private BlueprintParserFilesConfiguration searchForRightMapping(BlueprintArtifact blueprintArtifact) + BlueprintParserFilesConfiguration searchForRightMapping(BlueprintArtifact blueprintArtifact) throws SdcArtifactInstallerException { List<BlueprintParserFilesConfiguration> listConfig = new ArrayList<>(); Yaml yaml = new Yaml(); @@ -203,6 +203,15 @@ public class CsarInstallerImpl implements CsarInstaller { return node.toString(); } + private void createPolicyModel(CsarHandler csar) throws PolicyModelException { + try{ + Optional<String> policyModelYaml = csar.getPolicyModelYaml(); + // save policy model into the database + } catch (IOException e) { + throw new PolicyModelException("TransformerException when decoding the YamlText", e); + } + } + private static String searchForPolicyScopePrefix(BlueprintArtifact blueprintArtifact) throws SdcArtifactInstallerException { String policyName = null; diff --git a/src/main/java/org/onap/clamp/loop/LoopController.java b/src/main/java/org/onap/clamp/loop/LoopController.java index eeb6105b1..7e4517492 100644 --- a/src/main/java/org/onap/clamp/loop/LoopController.java +++ b/src/main/java/org/onap/clamp/loop/LoopController.java @@ -25,15 +25,16 @@ package org.onap.clamp.loop; import com.google.gson.JsonArray; import com.google.gson.reflect.TypeToken; + import java.lang.reflect.Type; import java.util.List; + import org.onap.clamp.clds.util.JsonUtils; import org.onap.clamp.policy.microservice.MicroServicePolicy; import org.onap.clamp.policy.operational.OperationalPolicy; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; - @Controller public class LoopController { @@ -67,4 +68,9 @@ public class LoopController { .fromJson(microServicePoliciesJson, MICROSERVICE_POLICY_TYPE); return loopService.updateMicroservicePolicies(loopName, microservicePolicies); } + + public String getSVGRepresentation(String loopName) { + return loopService.getClosedLoopModelSVG(loopName); + + } } diff --git a/src/main/java/org/onap/clamp/loop/LoopService.java b/src/main/java/org/onap/clamp/loop/LoopService.java index 7b79c112e..91b4bdf89 100644 --- a/src/main/java/org/onap/clamp/loop/LoopService.java +++ b/src/main/java/org/onap/clamp/loop/LoopService.java @@ -47,7 +47,7 @@ public class LoopService { this.operationalPolicyService = operationalPolicyService; } - Loop addNewLoop(Loop loop) { + Loop saveOrUpdateLoop(Loop loop) { return loopsRepository.save(loop); } diff --git a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java index e5b333dbb..7ebe0edb2 100644 --- a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java +++ b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java @@ -39,9 +39,9 @@ import javax.persistence.Table; import org.hibernate.annotations.Type; import org.hibernate.annotations.TypeDef; import org.hibernate.annotations.TypeDefs; +import org.onap.clamp.dao.model.jsontype.StringJsonUserType; import org.onap.clamp.loop.Loop; import org.onap.clamp.policy.Policy; -import org.onap.clamp.dao.model.jsontype.StringJsonUserType; @Entity @Table(name = "micro_service_policies") @@ -66,7 +66,6 @@ public class MicroServicePolicy implements Serializable, Policy { @Column(name = "shared", nullable = false) private Boolean shared; - @Expose @Column(name = "policy_tosca", nullable = false) private String policyTosca; @@ -79,7 +78,7 @@ public class MicroServicePolicy implements Serializable, Policy { private Set<Loop> usedByLoops = new HashSet<>(); public MicroServicePolicy() { - //serialization + // serialization } public MicroServicePolicy(String name, String policyTosca, Boolean shared, JsonObject jsonRepresentation, @@ -91,6 +90,7 @@ public class MicroServicePolicy implements Serializable, Policy { this.usedByLoops = usedByLoops; } + @Override public String getName() { return name; } @@ -119,6 +119,7 @@ public class MicroServicePolicy implements Serializable, Policy { this.policyTosca = policyTosca; } + @Override public JsonObject getJsonRepresentation() { return jsonRepresentation; } diff --git a/src/main/resources/clds/camel/rest/clamp-api-v2.xml b/src/main/resources/clds/camel/rest/clamp-api-v2.xml index 0a72a0c12..442375278 100644 --- a/src/main/resources/clds/camel/rest/clamp-api-v2.xml +++ b/src/main/resources/clds/camel/rest/clamp-api-v2.xml @@ -13,6 +13,21 @@ <to uri="bean:org.onap.clamp.loop.LoopController?method=getLoop(${header.loopName})" /> </get> + <get uri="/v2/loop/svgRepresentation/{loopName}" + outType="java.lang.String" + + produces="application/xml"> + <to + uri="bean:org.onap.clamp.loop.LoopController?method=getSVGRepresentation(${header.loopName})" /> + </get> + <post uri="/v2/loop/globalProperties/{loopName}" + type="com.google.gson.JsonArray" + consumes="application/json" + outType="org.onap.clamp.loop.Loop" + produces="application/json"> + <to + uri="bean:org.onap.clamp.loop.LoopController?method=updateOperationalPolicies(${header.loopName},${body})" /> + </post> <post uri="/v2/loop/updateOperationalPolicies/{loopName}" type="com.google.gson.JsonArray" consumes="application/json" diff --git a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImplTest.java b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImplTest.java index a995c523d..1fe3ff3d9 100644 --- a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImplTest.java +++ b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImplTest.java @@ -17,50 +17,161 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END============================================ + * * Modifications copyright (c) 2019 Nokia * =================================================================== * */ -package org.onap.clamp.clds.sdc.controller.installer; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +package org.onap.clamp.clds.sdc.controller.installer; import com.google.gson.JsonObject; import java.io.IOException; +import java.io.InputStream; +import org.apache.commons.io.IOUtils; +import org.assertj.core.api.Assertions; +import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.clamp.clds.client.DcaeInventoryServices; +import org.onap.clamp.clds.config.sdc.BlueprintParserFilesConfiguration; +import org.onap.clamp.clds.dao.CldsDao; +import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException; +import org.onap.clamp.clds.service.CldsService; +import org.onap.clamp.clds.service.CldsTemplateService; +import org.onap.clamp.clds.transform.XslTransformer; import org.onap.clamp.clds.util.JsonUtils; import org.onap.clamp.clds.util.ResourceFileUtil; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.notification.IResourceInstance; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.toscaparser.api.elements.Metadata; +import org.springframework.context.ApplicationContext; +import org.springframework.core.io.Resource; +@RunWith(MockitoJUnitRunner.class) public class CsarInstallerImplTest { + @Mock + private CsarHandler csarHandler; + + @Mock + private ApplicationContext applicationContext; + + @Mock + private DcaeInventoryServices dcaeInventoryServices; + + @Mock + private IResourceInstance resourceInstance; + + @Mock + private CldsService cldsService; + + @Mock + private INotificationData notificationData; + + @Mock + private Metadata metadata; + + @Mock + private ISdcCsarHelper sdcCsarHelper; + + private CsarInstallerImpl csarInstaller; + private BlueprintArtifact artifact; + + /** + * Set up method. + * throws: Exception + */ + @Before + public void setUp() throws Exception { + String dceaBlueprint = ResourceFileUtil.getResourceAsString("tosca/dcea_blueprint.yml"); + artifact = prepareBlueprintArtifact(dceaBlueprint); + csarInstaller = new CsarInstallerImpl(applicationContext, new CldsDao(), new CldsTemplateService(), + cldsService, dcaeInventoryServices, new XslTransformer()); + } + @Test - public void shouldReturnInputParametersFromBlueprint() throws IOException { + public void shouldReturnInputParametersFromBlueprint() { //given String expectedBlueprintInputsText = "{\"aaiEnrichmentHost\":\"aai.onap.svc.cluster.local\"" - + ",\"aaiEnrichmentPort\":\"8443\"" - + ",\"enableAAIEnrichment\":true" - + ",\"dmaap_host\":\"message-router\"" - + ",\"dmaap_port\":\"3904\"" - + ",\"enableRedisCaching\":false" - + ",\"redisHosts\":\"dcae-redis:6379\"" - + ",\"tag_version\":\"nexus3.onap.org:10001/onap/org.onap.dcaegen2.deployments.tca-cdap-container:1.1.0\"" - + ",\"consul_host\":\"consul-server\"" - + ",\"consul_port\":\"8500\",\"cbs_host\":\"{\\\"test\\\":" - + "{\\\"test\\\":\\\"test\\\"}}\",\"cbs_port\":\"10000\"" - + ",\"external_port\":\"32010\",\"policy_id\":\"AUTO_GENERATED_POLICY_ID_AT_SUBMIT\"}"; + + ",\"aaiEnrichmentPort\":\"8443\"" + + ",\"enableAAIEnrichment\":true" + + ",\"dmaap_host\":\"message-router\"" + + ",\"dmaap_port\":\"3904\"" + + ",\"enableRedisCaching\":false" + + ",\"redisHosts\":\"dcae-redis:6379\"" + + ",\"tag_version\":" + + "\"nexus3.onap.org:10001/onap/org.onap.dcaegen2.deployments.tca-cdap-container:1.1.0\"" + + ",\"consul_host\":\"consul-server\"" + + ",\"consul_port\":\"8500\",\"cbs_host\":\"{\\\"test\\\":" + + "{\\\"test\\\":\\\"test\\\"}}\",\"cbs_port\":\"10000\"" + + ",\"external_port\":\"32010\",\"policy_id\":\"AUTO_GENERATED_POLICY_ID_AT_SUBMIT\"}"; JsonObject expectedBlueprintInputs = JsonUtils.GSON.fromJson(expectedBlueprintInputsText, JsonObject.class); - String dceaBlueprint = ResourceFileUtil.getResourceAsString("tosca/dcea_blueprint.yml"); - BlueprintArtifact blueprintArtifact = mock(BlueprintArtifact.class); - when(blueprintArtifact.getDcaeBlueprint()).thenReturn(dceaBlueprint); - CsarInstallerImpl csarInstaller = new CsarInstallerImpl(); + //when + String parametersInJson = csarInstaller.getAllBlueprintParametersInJson(artifact); + //then + Assertions.assertThat(JsonUtils.GSON.fromJson(parametersInJson, JsonObject.class)) + .isEqualTo(expectedBlueprintInputs); + } + @Test + public void shouldReturnBuildModelName() throws SdcArtifactInstallerException { + //given + String expectedModelName = "CLAMP_test_name_" + + "vtest_service_version_" + + "test_resource_instance_name_" + + "test_artifact_name"; + prepareMockCsarHandler("name", "test_name", + "test_service_version"); + Mockito.when(resourceInstance.getResourceInstanceName()).thenReturn("test_resource_instance_name"); //when - String parametersInJson = csarInstaller.getAllBlueprintParametersInJson(blueprintArtifact); + String actualModelName = CsarInstallerImpl.buildModelName(csarHandler, artifact); + //then + Assertions.assertThat(actualModelName).isEqualTo(expectedModelName); + } + + @Test + public void shouldReturnRightMapping() throws SdcArtifactInstallerException, IOException { + //given + String input = "[{\"blueprintKey\":\"tca_k8s\"," + + "\"dcaeDeployable\":false," + + "\"files\":{\"svgXmlFilePath\":\"samplePath\",\"bpmnXmlFilePath\":\"samplePath\"}}]"; + BlueprintParserFilesConfiguration filesConfiguration = new BlueprintParserFilesConfiguration(); + filesConfiguration.setBpmnXmlFilePath("samplePath"); + filesConfiguration.setSvgXmlFilePath("samplePath"); + Resource resource = Mockito.mock(Resource.class); + InputStream inputStream = IOUtils.toInputStream(input, "UTF-8"); + Mockito.when(applicationContext.getResource(Mockito.any(String.class))).thenReturn(resource); + Mockito.when(resource.getInputStream()).thenReturn(inputStream); + csarInstaller.loadConfiguration(); + //when + BlueprintParserFilesConfiguration configuration = csarInstaller.searchForRightMapping(artifact); //then - assertThat(JsonUtils.GSON.fromJson(parametersInJson, JsonObject.class)).isEqualTo(expectedBlueprintInputs); + Assertions.assertThat(configuration.getBpmnXmlFilePath()).isEqualTo("samplePath"); + Assertions.assertThat(configuration.getSvgXmlFilePath()).isEqualTo("samplePath"); + } + + private BlueprintArtifact prepareBlueprintArtifact(String dceaBlueprint) { + artifact = new BlueprintArtifact(); + artifact.setBlueprintArtifactName("test_artifact_name"); + artifact.setBlueprintInvariantServiceUuid("test_inv_uuid"); + artifact.setResourceAttached(resourceInstance); + artifact.setDcaeBlueprint(dceaBlueprint); + return artifact; + } + + private void prepareMockCsarHandler(String metadataNameMockInput, String metadataNameMockOutput, + String serviceVersion) { + Mockito.when(csarHandler.getSdcCsarHelper()).thenReturn(sdcCsarHelper); + Mockito.when(sdcCsarHelper.getServiceMetadata()).thenReturn(metadata); + Mockito.when(metadata.getValue(metadataNameMockInput)).thenReturn(metadataNameMockOutput); + Mockito.when(csarHandler.getSdcNotification()).thenReturn(notificationData); + Mockito.when(notificationData.getServiceVersion()).thenReturn(serviceVersion); } }
\ No newline at end of file diff --git a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java index a9c308737..b7781bf2c 100644 --- a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java +++ b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java @@ -70,7 +70,7 @@ public class LoopServiceTestItCase { testLoop.setLastComputedState(LoopState.DESIGN); //when - Loop actualLoop = loopService.addNewLoop(testLoop); + Loop actualLoop = loopService.saveOrUpdateLoop(testLoop); //then assertThat(actualLoop).isNotNull(); @@ -166,7 +166,7 @@ public class LoopServiceTestItCase { private void saveTestLoopToDb() { Loop testLoop = createTestLoop(EXAMPLE_LOOP_NAME, "blueprint", "representation"); testLoop.setGlobalPropertiesJson(JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class)); - loopService.addNewLoop(testLoop); + loopService.saveOrUpdateLoop(testLoop); } @Test |