From: Sébastien Determe Date: Mon, 9 Mar 2020 09:22:24 +0000 (+0000) Subject: Merge "CLAMP-CDS integration to display all CDS actions for blueprint in CL" X-Git-Tag: 5.0.0~26 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=5c3a825851bb1a345620c5c4951726c5b94a0341;hp=-c;p=clamp.git Merge "CLAMP-CDS integration to display all CDS actions for blueprint in CL" --- 5c3a825851bb1a345620c5c4951726c5b94a0341 diff --combined src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java index 82cfcf4e,7cf06dcf..b0e8b0c3 --- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java +++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java @@@ -4,6 -4,7 +4,7 @@@ * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights * reserved. + * Modifications Copyright (C) 2020 Huawei Technologies Co., Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@@ -50,8 -51,6 +51,8 @@@ import javax.persistence.Table import javax.persistence.Transient; import org.hibernate.annotations.TypeDef; import org.hibernate.annotations.TypeDefs; +import org.onap.clamp.clds.tosca.ToscaYamlToJsonConvertor; +import org.onap.clamp.clds.util.JsonUtils; import org.onap.clamp.dao.model.jsontype.StringJsonUserType; import org.onap.clamp.loop.Loop; import org.onap.clamp.loop.template.LoopElementModel; @@@ -81,6 -80,12 +82,6 @@@ public class OperationalPolicy extends @JoinColumn(name = "loop_id", nullable = false) private Loop loop; - @Expose - @ManyToOne(fetch = FetchType.EAGER) - @JoinColumns({@JoinColumn(name = "policy_model_type", referencedColumnName = "policy_model_type"), - @JoinColumn(name = "policy_model_version", referencedColumnName = "version")}) - private PolicyModel policyModel; - public OperationalPolicy() { // Serialization } @@@ -106,32 -111,16 +107,32 @@@ this.setPdpGroup(pdpGroup); this.setPdpSubgroup(pdpSubgroup); this.setLoopElementModel(loopElementModel); - if (policyModel != null && policyModel.getPolicyModelType().contains("legacy")) { - LegacyOperationalPolicy.preloadConfiguration(configurationsJson, loop); + this.setJsonRepresentation(this.generateJsonRepresentation(policyModel)); + + } + + private JsonObject generateJsonRepresentation(PolicyModel policyModel) { + JsonObject jsonReturned = new JsonObject(); + if (policyModel == null) { + return new JsonObject(); } try { - this.setJsonRepresentation( - OperationalPolicyRepresentationBuilder.generateOperationalPolicySchema(loop.getModelService())); + if (isLegacy()) { + // Op policy Legacy case + LegacyOperationalPolicy.preloadConfiguration(jsonReturned, loop); + this.setJsonRepresentation( + OperationalPolicyRepresentationBuilder.generateOperationalPolicySchema(loop.getModelService())); + } else { + // Generic Case + this.setJsonRepresentation(JsonUtils.GSON + .fromJson(new ToscaYamlToJsonConvertor().parseToscaYaml(policyModel.getPolicyModelTosca(), + policyModel.getPolicyModelType()), JsonObject.class)); + } } catch (JsonSyntaxException | IOException | NullPointerException e) { logger.error("Unable to generate the operational policy Schema ... ", e); this.setJsonRepresentation(new JsonObject()); } + return jsonReturned; } public void setLoop(Loop loopName) { @@@ -157,6 -146,24 +158,6 @@@ this.name = name; } - /** - * policyModel getter. - * - * @return the policyModel - */ - public PolicyModel getPolicyModel() { - return policyModel; - } - - /** - * policyModel setter. - * - * @param policyModel the policyModel to set - */ - public void setPolicyModel(PolicyModel policyModel) { - this.policyModel = policyModel; - } - @Override public int hashCode() { final int prime = 31; @@@ -187,10 -194,6 +188,10 @@@ return true; } + public Boolean isLegacy() { + return (this.getPolicyModel() != null) && this.getPolicyModel().getPolicyModelType().contains("legacy"); + } + /** * Create policy Yaml from json defined here. * @@@ -220,7 -223,7 +221,7 @@@ metadata.addProperty("policy-id", this.name); operationalPolicyDetails.add("properties", LegacyOperationalPolicy - .reworkPayloadAttributes(this.getConfigurationsJson().get("operational_policy").deepCopy())); + .reworkActorAttributes(this.getConfigurationsJson().get("operational_policy").deepCopy())); DumperOptions options = new DumperOptions(); options.setIndent(2); @@@ -233,22 -236,17 +234,22 @@@ @Override public String createPolicyPayload() throws UnsupportedEncodingException { - // Now using the legacy payload fo Dublin - JsonObject payload = new JsonObject(); - payload.addProperty("policy-id", this.getName()); - payload.addProperty("content", - URLEncoder.encode( - LegacyOperationalPolicy - .createPolicyPayloadYamlLegacy(this.getConfigurationsJson().get("operational_policy")), - StandardCharsets.UTF_8.toString())); - String opPayload = new GsonBuilder().setPrettyPrinting().create().toJson(payload); - logger.info("Operational policy payload: " + opPayload); - return opPayload; + if (isLegacy()) { + // Now using the legacy payload fo Dublin + JsonObject payload = new JsonObject(); + payload.addProperty("policy-id", this.getName()); + payload.addProperty("content", + URLEncoder.encode( + LegacyOperationalPolicy + .createPolicyPayloadYamlLegacy( + this.getConfigurationsJson().get("operational_policy")), + StandardCharsets.UTF_8.toString())); + String opPayload = new GsonBuilder().setPrettyPrinting().create().toJson(payload); + logger.info("Operational policy payload: " + opPayload); + return opPayload; + } else { + return super.createPolicyPayload(); + } } /** diff --combined src/main/resources/application.properties index e856743a,3abbcd57..ed7f4ef4 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@@ -73,7 -73,7 +73,7 @@@ server.ssl.trust-store-password=enc:iDn server.servlet.context-path=/ #Modified engine-rest applicationpath -spring.profiles.active=clamp-default,clamp-aaf-authentication,clamp-sdc-controller,clamp-ssl-config,clamp-policy-controller +spring.profiles.active=clamp-default,clamp-aaf-authentication,clamp-sdc-controller,clamp-ssl-config,clamp-policy-controller,legacy-operational-policy spring.http.converters.preferred-json-mapper=gson #The max number of active threads in this pool @@@ -143,6 -143,12 +143,6 @@@ clamp.config.files.cldsUsers=classpath: clamp.config.files.globalProperties=classpath:/clds/templates/globalProperties.json clamp.config.files.sdcController=classpath:/clds/sdc-controllers-config.json -# Properties for Clamp -# DCAE request build properties -# -clamp.config.dcae.template=classpath:/clds/templates/dcae-template.json -clamp.config.dcae.deployment.template=classpath:/clds/templates/dcae-deployment-template.json -# # # Configuration Settings for Policy Engine Components clamp.config.policy.api.url=http4://policy.api.simpledemo.onap.org:6969 @@@ -152,9 -158,36 +152,9 @@@ clamp.config.policy.pap.url=http4://pol clamp.config.policy.pap.userName=healthcheck clamp.config.policy.pap.password=zb!XztG34 -# TCA MicroService Policy request build properties -# -clamp.config.tca.policyid.prefix=DCAE.Config_ -clamp.config.tca.policy.template=classpath:/clds/templates/tca-policy-template.json -clamp.config.tca.template=classpath:/clds/templates/tca-template.json -clamp.config.tca.thresholds.template=classpath:/clds/templates/tca-thresholds-template.json - -# -# -# Operational Policy request build properties -# -clamp.config.op.policyDescription=from CLAMP -# default -clamp.config.op.templateName=ClosedLoopControlName -clamp.config.op.operationTopic=APPC-CL -clamp.config.op.notificationTopic=POLICY-CL-MGT -clamp.config.op.controller=amsterdam -clamp.config.op.policy.appc=APPC # # Sdc service properties clamp.config.sdc.csarFolder = /tmp/sdc-controllers -clamp.config.sdc.blueprint.parser.mapping = classpath:/clds/blueprint-parser-mapping.json -# -clamp.config.ui.location.default=classpath:/clds/templates/ui-location-default.json -# -# if action.test.override is true, then any action will be marked as test=true (even if incoming action request had test=false); otherwise, test flag will be unchanged on the action request -clamp.config.action.test.override=false -# if action.insert.test.event is true, then insert event even if the action is set to test -clamp.config.action.insert.test.event=false -clamp.config.clds.service.cache.invalidate.after.seconds=120 #DCAE Inventory Url Properties clamp.config.dcae.inventory.url=http4://dcae.api.simpledemo.onap.org:8080 @@@ -190,3 -223,8 +190,8 @@@ clamp.config.cadi.cadiX509Issuers=CN=in ## Tosca converter clamp.config.tosca.converter.templates=classpath:/clds/tosca_updates/templates.properties + + # Configuration settings for CDS + clamp.config.cds.url=http4://blueprints-processor-http:8080 + clamp.config.cds.userName=ccsdkapps + clamp.config.cds.password=ccsdkapps diff --combined src/test/resources/application.properties index e842abd4,4f1a845c..54ba0900 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@@ -128,6 -128,12 +128,6 @@@ clamp.config.files.cldsUsers=classpath: clamp.config.files.globalProperties=classpath:/clds/templates/globalProperties.json clamp.config.files.sdcController=classpath:/clds/sdc-controllers-config.json -# Properties for Clamp -# DCAE request build properties -# -clamp.config.dcae.template=classpath:/clds/templates/dcae-template.json -clamp.config.dcae.deployment.template=classpath:/clds/templates/dcae-deployment-template.json -# # # Configuration Settings for Policy Engine Components clamp.config.policy.api.url=http4://localhost:${docker.http-cache.port.host} @@@ -137,9 -143,37 +137,9 @@@ clamp.config.policy.pap.url=http4://loc clamp.config.policy.pap.userName=healthcheck clamp.config.policy.pap.password=zb!XztG34 -# TCA MicroService Policy request build properties -# -clamp.config.tca.policyid.prefix=DCAE.Config_ -clamp.config.tca.policy.template=classpath:/clds/templates/tca-policy-template.json -clamp.config.tca.template=classpath:/clds/templates/tca-template.json -clamp.config.tca.thresholds.template=classpath:/clds/templates/tca-thresholds-template.json - -# -# -# Operational Policy request build properties -# -clamp.config.op.policyDescription=from clds -# default -clamp.config.op.templateName=ClosedLoopControlName -clamp.config.op.operationTopic=APPC-CL -clamp.config.op.notificationTopic=POLICY-CL-MGT -clamp.config.op.controller=amsterdam -clamp.config.op.policy.appc=APPC -# # Sdc service properties # clamp.config.sdc.csarFolder = ${project.build.directory}/sdc-tests -clamp.config.sdc.blueprint.parser.mapping = classpath:/clds/blueprint-parser-mapping.json -# -clamp.config.ui.location.default=classpath:/clds/templates/ui-location-default.json -# -# if action.test.override is true, then any action will be marked as test=true (even if incoming action request had test=false); otherwise, test flag will be unchanged on the action request -clamp.config.action.test.override=false -# if action.insert.test.event is true, then insert event even if the action is set to test -clamp.config.action.insert.test.event=false -clamp.config.clds.service.cache.invalidate.after.seconds=120 #DCAE Inventory Url Properties clamp.config.dcae.inventory.url=http4://localhost:${docker.http-cache.port.host} @@@ -160,4 -194,9 +160,9 @@@ clamp.config.security.permission.type.t clamp.config.security.permission.type.tosca=permission-type-tosca #This one indicates the type of instances (dev|prod|perf...), this must be set accordingly in clds-users.properties clamp.config.security.permission.instance=dev - clamp.config.security.authentication.class=org.onap.aaf.cadi.principal.X509Principal + clamp.config.security.authentication.class=org.onap.aaf.cadi.principal.X509Principal + + # Configuration settings for CDS + clamp.config.cds.url=http4://localhost:${docker.http-cache.port.host} + clamp.config.cds.userName=ccsdkapps + clamp.config.cds.password=ccsdkapps diff --combined src/test/resources/tosca/operational-policy-payload.yaml index 4e667e59,553a8afd..69c86cc8 --- a/src/test/resources/tosca/operational-policy-payload.yaml +++ b/src/test/resources/tosca/operational-policy-payload.yaml @@@ -1,11 -1,11 +1,11 @@@ tosca_definitions_version: tosca_simple_yaml_1_0_0 topology_template: policies: - - testPolicy: + - testPolicy.legacy: type: onap.policies.controlloop.Operational version: 1.0.0 metadata: - policy-id: testPolicy + policy-id: testPolicy.legacy properties: controlLoop: timeout: '0' @@@ -14,13 -14,8 +14,8 @@@ controlLoopName: LOOP_ASJOy_v1_0_ResourceInstanceName1_tca policies: - id: policy1 - recipe: Restart retry: '0' timeout: '0' - actor: APPC - payload: - requestParameters: '{"usePreload":true,"userParams":[]}' - configurationParameters: '[{"ip-addr":"$.vf-module-topology.vf-module-parameters.param[10].value","oam-ip-addr":"$.vf-module-topology.vf-module-parameters.param[15].value","enabled":"$.vf-module-topology.vf-module-parameters.param[22].value"}]' success: final_success failure: policy2 failure_timeout: final_failure_timeout @@@ -30,12 -25,14 +25,14 @@@ target: type: VNF resourceID: vLoadBalancerMS + actor: APPC + recipe: Restart + payload: + requestParameters: '{"usePreload":true,"userParams":[]}' + configurationParameters: '[{"ip-addr":"$.vf-module-topology.vf-module-parameters.param[10].value","oam-ip-addr":"$.vf-module-topology.vf-module-parameters.param[15].value","enabled":"$.vf-module-topology.vf-module-parameters.param[22].value"}]' - id: policy2 - recipe: VF Module Create retry: '0' timeout: '0' - actor: SO - payload: '' success: final_success failure: final_failure failure_timeout: final_failure_timeout @@@ -50,3 -47,6 +47,6 @@@ modelName: Vloadbalancerms..vpkg..module-1 modelVersion: '1' modelCustomizationId: 1bffdc31-a37d-4dee-b65c-dde623a76e52 + actor: SO + recipe: VF Module Create + payload: ''