diff options
Diffstat (limited to 'src')
15 files changed, 342 insertions, 177 deletions
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/java/org/onap/clamp/loop/LoopOperation.java b/src/main/java/org/onap/clamp/loop/LoopOperation.java index 518830aa0..87effa5fd 100644 --- a/src/main/java/org/onap/clamp/loop/LoopOperation.java +++ b/src/main/java/org/onap/clamp/loop/LoopOperation.java @@ -30,6 +30,7 @@ import com.google.gson.JsonObject; import java.io.IOException; import java.util.Iterator; import java.util.Set; +import java.util.UUID; import org.apache.camel.Exchange; import org.apache.camel.Message; @@ -52,8 +53,7 @@ public class LoopOperation { private static final String DCAE_STATUS_FIELD = "status"; private static final String DCAE_SERVICETYPE_ID = "serviceTypeId"; private static final String DCAE_INPUTS = "inputs"; - private static final String DCAE_DEPLOYMENT_PREFIX = "closedLoop_"; - private static final String DCAE_DEPLOYMENT_SUFIX = "_deploymentId"; + private static final String DCAE_DEPLOYMENT_PREFIX = "CLAMP_"; private static final String DEPLOYMENT_PARA = "dcaeDeployParameters"; private final LoopService loopService; @@ -63,8 +63,11 @@ public class LoopOperation { /** * The constructor. - * @param loopService The loop service - * @param refProp The clamp properties + * + * @param loopService + * The loop service + * @param refProp + * The clamp properties */ @Autowired public LoopOperation(LoopService loopService) { @@ -74,9 +77,11 @@ public class LoopOperation { /** * Get the payload used to send the deploy closed loop request. * - * @param loop The loop + * @param loop + * The loop * @return The payload used to send deploy closed loop request - * @throws IOException IOException + * @throws IOException + * IOException */ public String getDeployPayload(Loop loop) throws IOException { JsonObject globalProp = loop.getGlobalPropertiesJson(); @@ -98,9 +103,11 @@ public class LoopOperation { /** * Get the deployment id. * - * @param loop The loop + * @param loop + * The loop * @return The deployment id - * @throws IOException IOException + * @throws IOException + * IOException */ public String getDeploymentId(Loop loop) { // Set the deploymentId if not present yet @@ -109,7 +116,7 @@ public class LoopOperation { if (loop.getDcaeDeploymentId() != null && !loop.getDcaeDeploymentId().isEmpty()) { deploymentId = loop.getDcaeDeploymentId(); } else { - deploymentId = DCAE_DEPLOYMENT_PREFIX + loop.getName() + DCAE_DEPLOYMENT_SUFIX; + deploymentId = DCAE_DEPLOYMENT_PREFIX + UUID.randomUUID(); } return deploymentId; } @@ -117,10 +124,14 @@ public class LoopOperation { /** * Update the loop info. * - * @param camelExchange The camel exchange - * @param loop The loop - * @param deploymentId The deployment id - * @throws ParseException The parse exception + * @param camelExchange + * The camel exchange + * @param loop + * The loop + * @param deploymentId + * The deployment id + * @throws ParseException + * The parse exception */ public void updateLoopInfo(Exchange camelExchange, Loop loop, String deploymentId) throws ParseException { Message in = camelExchange.getIn(); @@ -133,20 +144,24 @@ public class LoopOperation { JSONObject linksObj = (JSONObject) jsonObj.get(DCAE_LINK_FIELD); String statusUrl = (String) linksObj.get(DCAE_STATUS_FIELD); - // use http4 instead of http, because camel http4 component is used to do the http call - String newStatusUrl = statusUrl.replaceAll("http:", "http4:"); - - loop.setDcaeDeploymentId(deploymentId); - loop.setDcaeDeploymentStatusUrl(newStatusUrl); + if (deploymentId == null) { + loop.setDcaeDeploymentId(null); + loop.setDcaeDeploymentStatusUrl(null); + } else { + loop.setDcaeDeploymentId(deploymentId); + loop.setDcaeDeploymentStatusUrl(statusUrl.replaceAll("http:", "http4:").replaceAll("https:", "https4:")); + } loopService.saveOrUpdateLoop(loop); } /** * Get the Closed Loop status based on the reply from Policy. * - * @param statusCode The status code + * @param statusCode + * The status code * @return The state based on policy response - * @throws ParseException The parse exception + * @throws ParseException + * The parse exception */ public String analysePolicyResponse(int statusCode) { if (statusCode == 200) { @@ -160,11 +175,12 @@ public class LoopOperation { /** * Get the name of the first Operational policy. * - * @param loop The closed loop + * @param loop + * The closed loop * @return The name of the first operational policy */ public String getOperationalPolicyName(Loop loop) { - Set<OperationalPolicy> opSet = (Set<OperationalPolicy>)loop.getOperationalPolicies(); + Set<OperationalPolicy> opSet = loop.getOperationalPolicies(); Iterator<OperationalPolicy> iterator = opSet.iterator(); while (iterator.hasNext()) { OperationalPolicy policy = iterator.next(); @@ -176,9 +192,11 @@ public class LoopOperation { /** * Get the Closed Loop status based on the reply from DCAE. * - * @param camelExchange The camel exchange + * @param camelExchange + * The camel exchange * @return The state based on DCAE response - * @throws ParseException The parse exception + * @throws ParseException + * The parse exception */ public String analyseDcaeResponse(Exchange camelExchange, Integer statusCode) throws ParseException { if (statusCode == null) { @@ -212,12 +230,17 @@ public class LoopOperation { } /** - * Update the status of the closed loop based on the response from Policy and DCAE. + * Update the status of the closed loop based on the response from Policy and + * DCAE. * - * @param loop The closed loop - * @param policyState The state get from Policy - * @param dcaeState The state get from DCAE - * @throws ParseException The parse exception + * @param loop + * The closed loop + * @param policyState + * The state get from Policy + * @param dcaeState + * The state get from DCAE + * @throws ParseException + * The parse exception */ public LoopState updateLoopStatus(Loop loop, TempLoopState policyState, TempLoopState dcaeState) { LoopState clState = LoopState.IN_ERROR; 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..cf758720a 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-loop" /> </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,25 +262,27 @@ 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> ${exchangeProperty[dcaeStatus]} == 'DEPLOYED' or ${exchangeProperty[dcaeStatus]} == 'IN_ERROR' or ${exchangeProperty[dcaeStatus]} == 'PROCESSING' </simple> - <to - uri="direct:undeploy-closedloop" /> + <to uri="direct:undeploy-loop" /> </when> <otherwise> <log loggingLevel="INFO" - message="Closed Loop is in state ${exchangeProperty[dcaeStatus]}, it can only be undeployed when in state DEPLOYED" /> + message="Closed Loop is in state ${exchangeProperty[dcaeStatus]}, it can only be undeployed when in state DEPLOYED/IN_ERROR/PROCESSING" /> <to 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> @@ -311,19 +314,17 @@ loggingLevel="INFO" message="Receive STOP request for loop: ${header.loopName}" /> <to - uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=startLog('Stop the closed loop')" /> + uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=startLog(*,'Stop the closed loop')" /> <to uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" /> <to uri="direct:load-loop" /> <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> @@ -342,7 +343,7 @@ </route> </put> <put - uri="/v2/loop/start/{loopName}" + uri="/v2/loop/restart/{loopName}" outType="org.onap.clamp.loop.Loop" produces="application/json"> <route> @@ -352,9 +353,9 @@ <doTry> <log loggingLevel="INFO" - message="Receive START request for loop: ${header.loopName}" /> + message="Receive RESTART request for loop: ${header.loopName}" /> <to - uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=startLog('Start the closed loop')" /> + uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=startLog(*,'Restart the closed loop')" /> <to uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" /> <to uri="direct:load-loop" /> @@ -363,11 +364,9 @@ <to uri="direct:add-all-to-active-pdp-group" /> <log loggingLevel="INFO" - message="START request successfully executed for loop: ${header.loopName}" /> + message="RESTART request successfully executed for loop: ${header.loopName}" /> <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})" /> + uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('RESTART request successfully executed','INFO',${exchangeProperty[loopObject]})" /> <to uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=endLog()" /> <doCatch> @@ -379,9 +378,9 @@ uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=errorLog()" /> <log loggingLevel="ERROR" - message="START request failed for loop: ${header.loopName}" /> + message="RESTART request failed for loop: ${header.loopName}" /> <to - uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('START request failed, Error reported: ${exception}','INFO',${exchangeProperty[loopObject]})" /> + uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('RESTART request failed, Error reported: ${exception}','INFO',${exchangeProperty[loopObject]})" /> </doCatch> </doTry> </route> @@ -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> @@ -504,7 +501,7 @@ loggingLevel="INFO" message="Receive DELETE request for loop: ${header.loopName}" /> <to - uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=startLog('Delete the closed loop')" /> + uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=startLog(*,'Delete the closed loop')" /> <to uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" /> <to uri="direct:load-loop" /> @@ -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..790a1679b 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" /> @@ -489,19 +489,14 @@ </doFinally> </doTry> </route> - <route id="deploy-closedloop"> - <from uri="direct:deploy-closedloop" /> + <route id="deploy-loop"> + <from uri="direct:deploy-loop" /> <doTry> <log loggingLevel="INFO" 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]})" /> @@ -540,19 +535,19 @@ <to uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()" /> <setProperty propertyName="logMessage"> - <simple>Deploy closed loop status</simple> + <simple>Deploy closed loop status (id:${exchangeProperty[deploymentId]})</simple> </setProperty> <to uri="direct:dump-loop-log-http-response" /> </doFinally> </doTry> </route> - <route id="undeploy-closedloop"> - <from uri="direct:undeploy-closedloop" /> + <route id="undeploy-loop"> + <from uri="direct:undeploy-loop" /> <doTry> <log loggingLevel="INFO" - message="UNdeploy the closed loop: ${exchangeProperty[loopObject].getName()} : ${exchangeProperty[loopObject].getDcaeDeploymentId()}" /> + message="Undeploy the closed loop: ${exchangeProperty[loopObject].getName()} : ${exchangeProperty[loopObject].getDcaeDeploymentId()}" /> <to uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=invokeLog('DCAE', 'Undeploy closed loop')" /> 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/java/org/onap/clamp/loop/LoopOperationTestItCase.java b/src/test/java/org/onap/clamp/loop/LoopOperationTestItCase.java index 93274788d..a2c97e0c0 100644 --- a/src/test/java/org/onap/clamp/loop/LoopOperationTestItCase.java +++ b/src/test/java/org/onap/clamp/loop/LoopOperationTestItCase.java @@ -55,15 +55,12 @@ public class LoopOperationTestItCase { LoopService loopService; private Loop createTestLoop() { - String yaml = "imports:\n" - + " - \"http://www.getcloudify.org/spec/cloudify/3.4/types.yaml\"\n" - + "node_templates:\n" - + " docker_service_host:\n" - + " type: dcae.nodes.SelectedDockerHost"; + String yaml = "imports:\n" + " - \"http://www.getcloudify.org/spec/cloudify/3.4/types.yaml\"\n" + + "node_templates:\n" + " docker_service_host:\n" + " type: dcae.nodes.SelectedDockerHost"; Loop loopTest = new Loop("ControlLoopTest", yaml, "<xml></xml>"); - loopTest.setGlobalPropertiesJson(new Gson().fromJson("{\"dcaeDeployParameters\":" - + "{\"policy_id\": \"name\"}}", JsonObject.class)); + loopTest.setGlobalPropertiesJson( + new Gson().fromJson("{\"dcaeDeployParameters\":" + "{\"policy_id\": \"name\"}}", JsonObject.class)); loopTest.setLastComputedState(LoopState.DESIGN); loopTest.setDcaeDeploymentId("123456789"); loopTest.setDcaeDeploymentStatusUrl("http4://localhost:8085"); @@ -71,14 +68,13 @@ public class LoopOperationTestItCase { MicroServicePolicy microServicePolicy = new MicroServicePolicy("configPolicyTest", "", "tosca_definitions_version: tosca_simple_yaml_1_0_0", true, - gson.fromJson("{\"configtype\":\"json\"}", JsonObject.class), new HashSet<>()); + gson.fromJson("{\"configtype\":\"json\"}", JsonObject.class), new HashSet<>()); microServicePolicy.setProperties(new Gson().fromJson("{\"param1\":\"value1\"}", JsonObject.class)); loopTest.addMicroServicePolicy(microServicePolicy); return loopTest; } - @Test public void testAnalysePolicyResponse() { LoopOperation loopOp = new LoopOperation(loopService); @@ -102,7 +98,7 @@ public class LoopOperationTestItCase { assertThat(opName1).isNull(); OperationalPolicy opPolicy1 = new OperationalPolicy("OperationalPolicyTest1", null, - gson.fromJson("{\"type\":\"Operational\"}", JsonObject.class)); + gson.fromJson("{\"type\":\"Operational\"}", JsonObject.class)); loop.addOperationalPolicy(opPolicy1); String opName2 = loopOp.getOperationalPolicyName(loop); assertThat(opName2).isEqualTo("OperationalPolicyTest1"); @@ -212,7 +208,7 @@ public class LoopOperationTestItCase { loopOp.updateLoopInfo(camelExchange, loop, "testNewId"); Loop newLoop = loopService.getLoop(loop.getName()); - String newDeployId = newLoop.getDcaeDeploymentId(); + String newDeployId = newLoop.getDcaeDeploymentId(); String newDeploymentStatusUrl = newLoop.getDcaeDeploymentStatusUrl(); assertThat(newDeployId).isEqualTo("testNewId"); @@ -228,11 +224,12 @@ public class LoopOperationTestItCase { loop.setDcaeDeploymentId(null); String deploymentId2 = loopOp.getDeploymentId(loop); - assertThat(deploymentId2).isEqualTo("closedLoop_ControlLoopTest_deploymentId"); + assertThat(deploymentId2).startsWith("CLAMP_"); loop.setDcaeDeploymentId(""); String deploymentId3 = loopOp.getDeploymentId(loop); - assertThat(deploymentId3).isEqualTo("closedLoop_ControlLoopTest_deploymentId"); + assertThat(deploymentId3).startsWith("CLAMP_"); + assertThat(deploymentId3).isNotEqualTo(deploymentId2); } @Test 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 |