diff options
15 files changed, 265 insertions, 120 deletions
@@ -24,7 +24,7 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.onap.clamp</groupId> <artifactId>clds</artifactId> - <version>4.0.0-SNAPSHOT</version> + <version>4.0.1-SNAPSHOT</version> <name>clamp</name> <!-- --> diff --git a/src/main/java/org/onap/clamp/clds/config/CamelConfiguration.java b/src/main/java/org/onap/clamp/clds/config/CamelConfiguration.java index 3a98788f5..de6e4dcdb 100644 --- a/src/main/java/org/onap/clamp/clds/config/CamelConfiguration.java +++ b/src/main/java/org/onap/clamp/clds/config/CamelConfiguration.java @@ -22,11 +22,34 @@ package org.onap.clamp.clds.config; +import java.io.IOException; +import java.net.URL; +import java.security.KeyManagementException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManagerFactory; + import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.http4.HttpClientConfigurer; +import org.apache.camel.component.http4.HttpComponent; import org.apache.camel.model.rest.RestBindingMode; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; +import org.apache.http.conn.scheme.Scheme; +import org.apache.http.conn.scheme.SchemeRegistry; +import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.socket.PlainConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLSocketFactory; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.conn.BasicHttpClientConnectionManager; import org.onap.clamp.clds.util.ClampVersioning; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; @Component @@ -35,8 +58,60 @@ public class CamelConfiguration extends RouteBuilder { @Autowired CamelContext camelContext; + @Autowired + private Environment env; + + private void configureDefaultSslProperties() { + if (env.getProperty("server.ssl.trust-store") != null) { + URL storeResource = CamelConfiguration.class + .getResource(env.getProperty("server.ssl.trust-store").replaceAll("classpath:", "")); + System.setProperty("javax.net.ssl.trustStore", storeResource.getPath()); + System.setProperty("javax.net.ssl.trustStorePassword", env.getProperty("server.ssl.trust-store-password")); + System.setProperty("javax.net.ssl.trustStoreType", "jks"); + System.setProperty("ssl.TrustManagerFactory.algorithm", "PKIX"); + storeResource = CamelConfiguration.class + .getResource(env.getProperty("server.ssl.key-store").replaceAll("classpath:", "")); + System.setProperty("javax.net.ssl.keyStore", storeResource.getPath()); + System.setProperty("javax.net.ssl.keyStorePassword", env.getProperty("server.ssl.key-store-password")); + System.setProperty("javax.net.ssl.keyStoreType", env.getProperty("server.ssl.key-store-type")); + } + } + + private void registerTrustStore() + throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException, CertificateException, IOException { + if (env.getProperty("server.ssl.trust-store") != null) { + KeyStore truststore = KeyStore.getInstance("JKS"); + truststore.load( + getClass().getClassLoader() + .getResourceAsStream(env.getProperty("server.ssl.trust-store").replaceAll("classpath:", "")), + env.getProperty("server.ssl.trust-store-password").toCharArray()); + + TrustManagerFactory trustFactory = TrustManagerFactory.getInstance("PKIX"); + trustFactory.init(truststore); + SSLContext sslcontext = SSLContext.getInstance("TLS"); + sslcontext.init(null, trustFactory.getTrustManagers(), null); + SSLSocketFactory factory = new SSLSocketFactory(sslcontext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); + SchemeRegistry registry = new SchemeRegistry(); + final Scheme scheme = new Scheme("https4", 443, factory); + registry.register(scheme); + ConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory(); + HttpComponent http4 = camelContext.getComponent("https4", HttpComponent.class); + http4.setHttpClientConfigurer(new HttpClientConfigurer() { + + @Override + public void configureHttpClient(HttpClientBuilder builder) { + builder.setSSLSocketFactory(factory); + Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() + .register("https", factory).register("http", plainsf).build(); + builder.setConnectionManager(new BasicHttpClientConnectionManager(registry)); + } + }); + } + } + @Override - public void configure() { + public void configure() + throws KeyManagementException, KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { restConfiguration().component("servlet").bindingMode(RestBindingMode.json).jsonDataFormat("clamp-gson") .dataFormatProperty("prettyPrint", "true")// .enableCORS(true) // turn on swagger api-doc @@ -45,5 +120,8 @@ public class CamelConfiguration extends RouteBuilder { .apiProperty("base.path", "/restservices/clds/"); // .apiProperty("cors", "true"); camelContext.setTracing(true); + + configureDefaultSslProperties(); + registerTrustStore(); } } diff --git a/src/main/java/org/onap/clamp/clds/config/spring/SSLConfiguration.java b/src/main/java/org/onap/clamp/clds/config/spring/SSLConfiguration.java deleted file mode 100644 index ac5849b80..000000000 --- a/src/main/java/org/onap/clamp/clds/config/spring/SSLConfiguration.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 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. - * 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.clamp.clds.config.spring; - -import java.net.URL; - -import javax.annotation.PostConstruct; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.Environment; - -@Configuration -public class SSLConfiguration { - @Autowired - private Environment env; - - @PostConstruct - private void configureSSL() { - if (env.getProperty("server.ssl.trust-store") != null) { - URL storeResource = SSLConfiguration.class - .getResource(env.getProperty("server.ssl.trust-store").replaceAll("classpath:", "")); - System.setProperty("javax.net.ssl.trustStore", storeResource.getPath()); - System.setProperty("javax.net.ssl.trustStorePassword", env.getProperty("server.ssl.trust-store-password")); - System.setProperty("javax.net.ssl.trustStoreType", env.getProperty("server.ssl.key-store-type")); - - storeResource = SSLConfiguration.class - .getResource(env.getProperty("server.ssl.key-store").replaceAll("classpath:", "")); - System.setProperty("javax.net.ssl.keyStore", storeResource.getPath()); - System.setProperty("javax.net.ssl.keyStorePassword", env.getProperty("server.ssl.key-store-password")); - System.setProperty("javax.net.ssl.keyStoreType", env.getProperty("server.ssl.key-store-type")); - } - } -}
\ No newline at end of file diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java index aca2ed01d..3792c1720 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java @@ -53,21 +53,23 @@ public class BlueprintParser { private static final String TYPE = "type"; private static final String PROPERTIES = "properties"; private static final String NAME = "name"; - private static final String POLICYID = "policy_id"; - private static final String POLICY_TYPEID = "policy_type_id"; + private static final String INPUT = "inputs"; + private static final String GET_INPUT = "get_input"; + private static final String POLICY_MODELID = "policy_model_id"; private static final String RELATIONSHIPS = "relationships"; private static final String CLAMP_NODE_RELATIONSHIPS_GETS_INPUT_FROM = "clamp_node.relationships.gets_input_from"; private static final String TARGET = "target"; public Set<MicroService> getMicroServices(String blueprintString) { Set<MicroService> microServices = new HashSet<>(); - JsonObject jsonObject = BlueprintParser.convertToJson(blueprintString); - JsonObject nodeTemplateList = jsonObject.get(NODE_TEMPLATES).getAsJsonObject(); + JsonObject blueprintJson = BlueprintParser.convertToJson(blueprintString); + JsonObject nodeTemplateList = blueprintJson.get(NODE_TEMPLATES).getAsJsonObject(); + JsonObject inputList = blueprintJson.get(INPUT).getAsJsonObject(); for (Entry<String, JsonElement> entry : nodeTemplateList.entrySet()) { JsonObject nodeTemplate = entry.getValue().getAsJsonObject(); if (nodeTemplate.get(TYPE).getAsString().contains(DCAE_NODES)) { - MicroService microService = getNodeRepresentation(entry, nodeTemplateList); + MicroService microService = getNodeRepresentation(entry, nodeTemplateList, inputList); microServices.add(microService); } } @@ -119,12 +121,12 @@ public class BlueprintParser { return ""; } - String findModelTypeInTargetArray(JsonArray jsonArray, JsonObject nodeTemplateList) { + String findModelTypeInTargetArray(JsonArray jsonArray, JsonObject nodeTemplateList, JsonObject inputList) { for (JsonElement elem : jsonArray) { String modelType = getModelType( new AbstractMap.SimpleEntry<String, JsonElement>(elem.getAsJsonObject().get(TARGET).getAsString(), nodeTemplateList.get(elem.getAsJsonObject().get(TARGET).getAsString()).getAsJsonObject()), - nodeTemplateList); + nodeTemplateList, inputList); if (!modelType.isEmpty()) { return modelType; } @@ -132,29 +134,34 @@ public class BlueprintParser { return ""; } - String getModelType(Entry<String, JsonElement> entry, JsonObject nodeTemplateList) { + String getModelType(Entry<String, JsonElement> entry, JsonObject nodeTemplateList, JsonObject inputList) { JsonObject ob = entry.getValue().getAsJsonObject(); // Search first in this node template if (ob.has(PROPERTIES)) { JsonObject properties = ob.get(PROPERTIES).getAsJsonObject(); - if (properties.has(POLICYID)) { - JsonObject policyIdObj = properties.get(POLICYID).getAsJsonObject(); - if (policyIdObj.has(POLICY_TYPEID)) { - return policyIdObj.get(POLICY_TYPEID).getAsString(); + if (properties.has(POLICY_MODELID)) { + if (properties.get(POLICY_MODELID).isJsonObject()) { + // it's a blueprint parameter + return inputList.get(properties.get(POLICY_MODELID).getAsJsonObject().get(GET_INPUT).getAsString()) + .getAsJsonObject().get("default").getAsString(); + } else { + // It's a direct value + return properties.get(POLICY_MODELID).getAsString(); } } } - // Then it's may be a relationship + // Or it's may be defined in a relationship if (ob.has(RELATIONSHIPS)) { - return findModelTypeInTargetArray(ob.get(RELATIONSHIPS).getAsJsonArray(), nodeTemplateList); + return findModelTypeInTargetArray(ob.get(RELATIONSHIPS).getAsJsonArray(), nodeTemplateList, inputList); } return ""; } - MicroService getNodeRepresentation(Entry<String, JsonElement> entry, JsonObject nodeTemplateList) { + MicroService getNodeRepresentation(Entry<String, JsonElement> entry, JsonObject nodeTemplateList, + JsonObject inputList) { String name = getName(entry); String getInputFrom = getInput(entry); - String modelType = getModelType(entry, nodeTemplateList); + String modelType = getModelType(entry, nodeTemplateList, inputList); return new MicroService(name, modelType, getInputFrom, ""); } 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 0d6d3cb2f..7e0c891ee 100644 --- a/src/main/resources/clds/camel/rest/clamp-api-v2.xml +++ b/src/main/resources/clds/camel/rest/clamp-api-v2.xml @@ -202,25 +202,21 @@ excludePattern="loopName" /> <doTry> <to - uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=startLog(*, 'Deploy the closed loop')" /> + uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=startLog(*, 'DEPLOY the closed loop')" /> <to uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" /> - <to - uri="direct:load-loop" /> - <to - uri="direct:get-status-from-policy" /> - <to - uri="direct:get-status-from-dcae" /> + <to uri="direct:load-loop" /> + <to uri="direct:get-status-from-policy" /> + <to uri="direct:get-status-from-dcae" /> <log loggingLevel="INFO" - message="policy status0000: ${exchangeProperty[policyStatus]}"></log> + message="Policy deployment status: ${exchangeProperty[policyStatus]}"></log> <choice> <when> <simple> ${exchangeProperty[policyStatus]} == 'SUBMITTED' and ${exchangeProperty[dcaeStatus]} == 'NOT_DEPLOYED' </simple> - <to - uri="direct:deploy-closedloop" /> + <to uri="direct:deploy-closedloop" /> </when> <otherwise> <log @@ -230,6 +226,11 @@ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('Closed Loop is in state ${exchangeProperty[policyStatus]}, it can only be deployed when in state SUBMIT','ERROR',${exchangeProperty[loopObject]})" /> </otherwise> </choice> + <log + loggingLevel="INFO" + message="DEPLOY request successfully executed for loop: ${header.loopName}" /> + <to + uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('DEPLOY request successfully executed','INFO',${exchangeProperty[loopObject]})" /> <to uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=endLog()" /> <doCatch> @@ -241,9 +242,9 @@ uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=errorLog()" /> <log loggingLevel="ERROR" - message="Deploy request failed for loop: ${header.loopName}" /> + message="DEPLOY request failed for loop: ${header.loopName}" /> <to - uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('Deploy request failed','ERROR',${exchangeProperty[loopObject]})" /> + uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('DEPLOY request failed, Error reported: ${exception}','ERROR',${exchangeProperty[loopObject]})" /> </doCatch> </doTry> </route> @@ -261,16 +262,13 @@ uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=startLog(*, 'Undeploy the closed loop')" /> <to uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" /> - <to - uri="direct:load-loop" /> - <to - uri="direct:get-status-from-dcae" /> + <to uri="direct:load-loop" /> + <to uri="direct:get-status-from-dcae" /> <choice> <when> <simple> ${exchangeProperty[dcaeStatus]} == 'DEPLOYED' </simple> - <to - uri="direct:undeploy-closedloop" /> + <to uri="direct:undeploy-closedloop" /> </when> <otherwise> <log @@ -280,6 +278,11 @@ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('Closed Loop is in state ${exchangeProperty[dcaeStatus]}, it can only be deployed when in state DEPLOYED','ERROR',${exchangeProperty[loopObject]})" /> </otherwise> </choice> + <log + loggingLevel="INFO" + message="UNDEPLOY request successfully executed for loop: ${header.loopName}" /> + <to + uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('UNDEPLOY request successfully executed','INFO',${exchangeProperty[loopObject]})" /> <to uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=endLog()" /> <doCatch> @@ -291,9 +294,9 @@ uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=errorLog()" /> <log loggingLevel="ERROR" - message="Undeploy request failed for loop: $${header.loopName}" /> + message="UNDEPLOY request failed for loop: ${header.loopName}" /> <to - uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('Undeploy request failed','ERROR',${exchangeProperty[loopObject]})" /> + uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('UNDEPLOY request failed, Error reported: ${exception}','ERROR',${exchangeProperty[loopObject]})" /> </doCatch> </doTry> </route> @@ -318,12 +321,10 @@ <to uri="direct:remove-all-policy-from-active-pdp-group" /> <log loggingLevel="INFO" - message="STOP request successfully executed for loop: ${body}" /> + message="STOP request successfully executed for loop: ${header.loopName}" /> <to uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('STOP request successfully executed','INFO',${exchangeProperty[loopObject]})" /> <to - uri="bean:org.onap.clamp.loop.LoopController?method=getLoop(${header.loopName})" /> - <to uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=endLog()" /> <doCatch> <exception>java.lang.Exception</exception> @@ -367,8 +368,6 @@ <to uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('START request successfully executed','INFO',${exchangeProperty[loopObject]})" /> <to - uri="bean:org.onap.clamp.loop.LoopController?method=getLoop(${header.loopName})" /> - <to uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=endLog()" /> <doCatch> <exception>java.lang.Exception</exception> @@ -475,8 +474,6 @@ <to uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('SUBMIT request successfully executed','INFO',${exchangeProperty[loopObject]})" /> <to - uri="bean:org.onap.clamp.loop.LoopController?method=getLoop(${header.loopName})" /> - <to uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=endLog()" /> <doCatch> <exception>java.lang.Exception</exception> @@ -581,7 +578,9 @@ outType="org.onap.clamp.loop.Loop" produces="application/json"> <route> - <removeHeaders pattern="*" excludePattern="loopName"/> + <removeHeaders + pattern="*" + excludePattern="loopName" /> <doTry> <log loggingLevel="INFO" @@ -618,7 +617,7 @@ loggingLevel="ERROR" message="Get Status request failed for loop: ${header.loopName}" /> <to - uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('Get Status request failed','ERROR',${exchangeProperty[loopObject]})" /> + uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('Get Status request failed, Error reported: ${exception}','ERROR',${exchangeProperty[loopObject]})" /> </doCatch> <doFinally> <to diff --git a/src/main/resources/clds/camel/routes/flexible-flow.xml b/src/main/resources/clds/camel/routes/flexible-flow.xml index 5f8577720..920e1e549 100644 --- a/src/main/resources/clds/camel/routes/flexible-flow.xml +++ b/src/main/resources/clds/camel/routes/flexible-flow.xml @@ -413,9 +413,9 @@ </setHeader> <log loggingLevel="INFO" - message="Endpoint to add policies to PDP Group: {{clamp.config.policy.pap.url}}/policy/pap/v1/pdps"></log> + message="Endpoint to add policies to PDP Group: {{clamp.config.policy.pap.url}}/policy/pap/v1/pdps/policies"></log> <toD - uri="{{clamp.config.policy.pap.url}}/policy/pap/v1/pdps?bridgeEndpoint=true&throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&httpClient.connectTimeout=10000&useSystemProperties=true&authUsername={{clamp.config.policy.pap.userName}}&authPassword={{clamp.config.policy.pap.password}}" /> + uri="{{clamp.config.policy.pap.url}}/policy/pap/v1/pdps/policies?bridgeEndpoint=true&throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&httpClient.connectTimeout=10000&useSystemProperties=true&authUsername={{clamp.config.policy.pap.userName}}&authPassword={{clamp.config.policy.pap.password}}" /> <doFinally> <to uri="direct:reset-raise-http-exception-flag" /> @@ -497,11 +497,6 @@ message="Deploy the closed loop: ${exchangeProperty[loopObject].getName()}" /> <to uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=invokeLog('DCAE', 'Deploy closed loop')" /> - <simple>${exchangeProperty[loopObject].getOperationalPolicies()} - </simple> - <setProperty propertyName="operationalPolicy"> - <simple>${body}</simple> - </setProperty> <setBody> <method ref="org.onap.clamp.loop.LoopOperation" method="getDeployPayload(${exchangeProperty[loopObject]})" /> diff --git a/src/test/java/org/onap/clamp/clds/client/GuardPolicyDeleteDelegateTest.java b/src/test/java/org/onap/clamp/clds/client/GuardPolicyDeleteDelegateTest.java new file mode 100644 index 000000000..2ff8166b9 --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/client/GuardPolicyDeleteDelegateTest.java @@ -0,0 +1,117 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2019 Samsung. 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.clamp.clds.client; + +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.apache.camel.Exchange; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.clamp.clds.client.req.policy.PolicyClient; +import org.onap.clamp.clds.exception.ModelBpmnException; + +@RunWith(MockitoJUnitRunner.class) +public class GuardPolicyDeleteDelegateTest { + + private static final String MODEL_BPMN_KEY = "modelBpmnProp"; + private static final String MODEL_PROP_KEY = "modelProp"; + private static final String TEST_KEY = "isTest"; + private static final String EVENT_ACTION_KEY = "eventAction"; + + private static final String POLICY_ID_FROM_JSON = "{policy:[{id:Policy_7,from:''}]}"; + private static final String TCA_ID_FROM_JSON = "{tca:[{id:'',from:''}]}"; + private static final String ID_JSON = "{Policy_7:{r:[" + + "{name:pid,value:pid334}," + + "{name:timeout,value:50}," + + "{name:policyType,value:pt}," + + "{policyConfigurations:[[" + + "{name:_id,value:ret345}," + + "{name:recipe,value:make}," + + "{name:maxRetries,value:5}," + + "{name:retryTimeLimit,value:100}," + + "{name:enableGuardPolicy,value:on}]]}]}}"; + private static final String NOT_JSON = "not json"; + private static final String EVENT_ACTION_VALUE = "action"; + + @Mock + private Exchange exchange; + + @Mock + private PolicyClient policyClient; + + @InjectMocks + private GuardPolicyDeleteDelegate guardPolicyDeleteDelegate; + + @Test + public void shouldExecuteSuccessfully() { + // given + when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(POLICY_ID_FROM_JSON); + when(exchange.getProperty(eq(MODEL_PROP_KEY))).thenReturn(ID_JSON); + when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false); + when(exchange.getProperty(eq(EVENT_ACTION_KEY))).thenReturn(EVENT_ACTION_VALUE); + + // when + guardPolicyDeleteDelegate.execute(exchange); + + // then + verify(policyClient).deleteGuard(any()); + } + + @Test + public void shouldExecutePolicyNotFound() { + // given + when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(TCA_ID_FROM_JSON); + when(exchange.getProperty(eq(MODEL_PROP_KEY))).thenReturn(ID_JSON); + when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false); + when(exchange.getProperty(eq(EVENT_ACTION_KEY))).thenReturn(EVENT_ACTION_VALUE); + + // when + guardPolicyDeleteDelegate.execute(exchange); + + // then + verify(policyClient, never()).deleteGuard(any()); + } + + @Test(expected = ModelBpmnException.class) + public void shouldThrowModelBpmnException() { + // given + when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(NOT_JSON); + when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false); + + // when + guardPolicyDeleteDelegate.execute(exchange); + } + + @Test(expected = NullPointerException.class) + public void shouldThrowNullPointerException() { + // when + guardPolicyDeleteDelegate.execute(exchange); + } +} diff --git a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java index 7a1f9f0ac..dec639770 100644 --- a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java +++ b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java @@ -144,7 +144,7 @@ public class BlueprintParserTest { MicroService expected = new MicroService(SECOND_APPP, MODEL_TYPE1, FIRST_APPP, ""); Entry<String, JsonElement> entry = jsonObject.entrySet().iterator().next(); - MicroService actual = new BlueprintParser().getNodeRepresentation(entry, jsonObject); + MicroService actual = new BlueprintParser().getNodeRepresentation(entry, jsonObject, null); Assert.assertEquals(expected, actual); } diff --git a/src/test/resources/clds/blueprint-with-microservice-chain.yaml b/src/test/resources/clds/blueprint-with-microservice-chain.yaml index 4a7e5d7aa..fa2d72052 100644 --- a/src/test/resources/clds/blueprint-with-microservice-chain.yaml +++ b/src/test/resources/clds/blueprint-with-microservice-chain.yaml @@ -31,7 +31,7 @@ node_templates: service_component_name_override: second_app image: { get_input: second_app_docker_image } policy_id: - policy_type_id: type2 + policy_model_id: "type2" interfaces: cloudify.interfaces.lifecycle: start: @@ -56,7 +56,7 @@ node_templates: image: { get_input: first_app_docker_image } container_port: 6565 policy_id: - policy_type_id: type1 + policy_model_id: "type1" interfaces: cloudify.interfaces.lifecycle: start: @@ -81,7 +81,7 @@ node_templates: image: { get_input: third_app_docker_image } container_port: 443 policy_id: - policy_type_id: type3 + policy_model_id: "type3" interfaces: cloudify.interfaces.lifecycle: start: diff --git a/src/test/resources/clds/single-microservice-fragment-valid.yaml b/src/test/resources/clds/single-microservice-fragment-valid.yaml index 269ee5062..2c1680717 100644 --- a/src/test/resources/clds/single-microservice-fragment-valid.yaml +++ b/src/test/resources/clds/single-microservice-fragment-valid.yaml @@ -6,7 +6,7 @@ second_app: image: { get_input: second_app_docker_image } name: second_app policy_id: - policy_type_id: type1 + policy_model_id: "type1" interfaces: cloudify.interfaces.lifecycle: start: diff --git a/src/test/resources/example/sdc/blueprint-dcae/prop-text-for-tca-3.json b/src/test/resources/example/sdc/blueprint-dcae/prop-text-for-tca-3.json index f8f531654..012c46e9c 100644 --- a/src/test/resources/example/sdc/blueprint-dcae/prop-text-for-tca-3.json +++ b/src/test/resources/example/sdc/blueprint-dcae/prop-text-for-tca-3.json @@ -40,7 +40,8 @@ "cbs_host": "config-binding-service.dcae.svc.cluster.local", "cbs_port": "10000", "external_port": "32012", - "policy_id": "AUTO_GENERATED_POLICY_ID_AT_SUBMIT" + "policy_id": "AUTO_GENERATED_POLICY_ID_AT_SUBMIT", + "policy_model_id": "onap.policies.monitoring.cdap.tca.hi.lo.app" } } ] diff --git a/src/test/resources/example/sdc/blueprint-dcae/tca.yaml b/src/test/resources/example/sdc/blueprint-dcae/tca.yaml index edaa0be28..0cb9cdb68 100644 --- a/src/test/resources/example/sdc/blueprint-dcae/tca.yaml +++ b/src/test/resources/example/sdc/blueprint-dcae/tca.yaml @@ -17,7 +17,7 @@ node_templates: properties: policy_id: get_input: policy_id - policy_type_id: onap.policies.monitoring.cdap.tca.hi.lo.app + policy_model_id: "onap.policies.monitoring.cdap.tca.hi.lo.app" cdap_host_host: type: dcae.nodes.StreamingAnalytics.SelectedCDAPInfrastructure properties: diff --git a/src/test/resources/example/sdc/blueprint-dcae/tca_2.yaml b/src/test/resources/example/sdc/blueprint-dcae/tca_2.yaml index 56ae32a7f..00ebfe7fe 100644 --- a/src/test/resources/example/sdc/blueprint-dcae/tca_2.yaml +++ b/src/test/resources/example/sdc/blueprint-dcae/tca_2.yaml @@ -171,4 +171,4 @@ node_templates: properties: policy_id: get_input: policy_id - policy_type_id: onap.policies.monitoring.cdap.tca.hi.lo.app + policy_model_id: "onap.policies.monitoring.cdap.tca.hi.lo.app" diff --git a/src/test/resources/example/sdc/blueprint-dcae/tca_3.yaml b/src/test/resources/example/sdc/blueprint-dcae/tca_3.yaml index 53cfc4f76..6fab504b2 100644 --- a/src/test/resources/example/sdc/blueprint-dcae/tca_3.yaml +++ b/src/test/resources/example/sdc/blueprint-dcae/tca_3.yaml @@ -51,6 +51,9 @@ inputs: type: string description: Kubernetes node port on which CDAPgui is exposed default: "32012" + policy_model_id: + type: string + default: "onap.policies.monitoring.cdap.tca.hi.lo.app" node_templates: tca_k8s: @@ -150,4 +153,5 @@ node_templates: properties: policy_id: get_input: policy_id - policy_type_id: onap.policies.monitoring.cdap.tca.hi.lo.app + policy_model_id: + get_input: policy_model_id diff --git a/version.properties b/version.properties index 937711c74..16b9934e3 100644 --- a/version.properties +++ b/version.properties @@ -27,7 +27,7 @@ major=4 minor=0 -patch=0 +patch=1 base_version=${major}.${minor}.${patch} |