aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java122
-rw-r--r--src/main/java/org/onap/clamp/clds/config/ClampProperties.java65
-rw-r--r--src/main/java/org/onap/clamp/clds/config/PolicyConfiguration.java133
-rw-r--r--src/main/java/org/onap/clamp/clds/config/spring/SdcControllerConfiguration.java4
-rw-r--r--src/main/java/org/onap/clamp/clds/exception/BadRequestException.java61
-rw-r--r--src/main/java/org/onap/clamp/clds/exception/sdc/controller/BlueprintParserException.java (renamed from src/main/java/org/onap/clamp/exception/OperationException.java)37
-rw-r--r--src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryCache.java2
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java5
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintMicroService.java (renamed from src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java)44
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java161
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/ChainGenerator.java24
-rwxr-xr-xsrc/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java8
-rwxr-xr-xsrc/main/java/org/onap/clamp/clds/util/drawing/Painter.java10
-rw-r--r--src/main/java/org/onap/clamp/clds/util/drawing/SvgFacade.java4
-rw-r--r--src/main/java/org/onap/clamp/loop/CsarInstaller.java68
-rw-r--r--src/main/java/org/onap/clamp/loop/Loop.java19
-rw-r--r--src/main/java/org/onap/clamp/loop/components/external/DcaeComponent.java13
-rw-r--r--src/main/java/org/onap/clamp/loop/template/LoopElementModel.java2
-rw-r--r--src/main/java/org/onap/clamp/loop/template/LoopTemplate.java25
-rw-r--r--src/main/java/org/onap/clamp/loop/template/PolicyModel.java10
-rw-r--r--src/main/java/org/onap/clamp/policy/downloader/PolicyDownloader.java96
21 files changed, 488 insertions, 425 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java b/src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java
new file mode 100644
index 000000000..96294207a
--- /dev/null
+++ b/src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java
@@ -0,0 +1,122 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2020 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.client;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.ExchangeBuilder;
+import org.onap.clamp.clds.config.ClampProperties;
+import org.onap.clamp.clds.sdc.controller.installer.BlueprintMicroService;
+import org.onap.clamp.loop.template.PolicyModel;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * The class implements the communication with the Policy Engine to retrieve
+ * policy models (tosca). It mainly delegates the physical calls to Camel
+ * engine.
+ *
+ */
+@Component
+public class PolicyEngineServices {
+ private final CamelContext camelContext;
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyEngineServices.class);
+ private static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
+ private static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
+ private static int retryInterval = 0;
+ private static int retryLimit = 1;
+
+ public static final String POLICY_RETRY_INTERVAL = "policy.retry.interval";
+ public static final String POLICY_RETRY_LIMIT = "policy.retry.limit";
+
+ @Autowired
+ public PolicyEngineServices(CamelContext camelContext, ClampProperties refProp) {
+ this.camelContext = camelContext;
+
+ if (refProp.getStringValue(POLICY_RETRY_LIMIT) != null) {
+ retryLimit = Integer.valueOf(refProp.getStringValue(POLICY_RETRY_LIMIT));
+ }
+ if (refProp.getStringValue(POLICY_RETRY_INTERVAL) != null) {
+ retryInterval = Integer.valueOf(refProp.getStringValue(POLICY_RETRY_INTERVAL));
+ }
+ }
+
+ public PolicyModel createPolicyModelFromPolicyEngine(String policyType, String policyVersion)
+ throws InterruptedException {
+ return new PolicyModel(policyType, this.downloadOnePolicy(policyType, policyVersion), policyVersion,
+ createPolicyAcronym(policyType));
+ }
+
+ public PolicyModel createPolicyModelFromPolicyEngine(BlueprintMicroService microService)
+ throws InterruptedException {
+ return createPolicyModelFromPolicyEngine(microService.getModelType(), microService.getModelVersion());
+ }
+
+ private static String createPolicyAcronym(String policyType) {
+ String[] policyNameArray = policyType.split("\\.");
+ return policyNameArray[policyNameArray.length - 1];
+ }
+
+ /**
+ * This method can be used to download all policy types + data types defined in
+ * policy engine.
+ *
+ * @return A yaml containing all policy Types and all data types
+ * @throws InterruptedException In case of issue when sleeping during the retry
+ */
+ public String downloadAllPolicies() throws InterruptedException {
+ return callCamelRoute(ExchangeBuilder.anExchange(camelContext).build(), "direct:get-all-policy-models");
+ }
+
+ /**
+ * This method can be used to download a policy tosca model on the engine.
+ *
+ * @param policyType The policy type (id)
+ * @param policyVersion The policy version
+ * @return A string with the whole policy tosca model
+ * @throws InterruptedException In case of issue when sleeping during the retry
+ */
+ public String downloadOnePolicy(String policyType, String policyVersion) throws InterruptedException {
+ return callCamelRoute(ExchangeBuilder.anExchange(camelContext).withProperty("policyModelName", policyType)
+ .withProperty("policyModelVersion", policyVersion).build(), "direct:get-policy-model");
+ }
+
+ private String callCamelRoute(Exchange exchange, String camelFlow) throws InterruptedException {
+ for (int i = 0; i < retryLimit; i++) {
+ Exchange exchangeResponse = camelContext.createProducerTemplate().send(camelFlow, exchange);
+ if (Integer.valueOf(200).equals(exchangeResponse.getIn().getHeader("CamelHttpResponseCode"))) {
+ return (String) exchangeResponse.getIn().getBody();
+ } else {
+ logger.info("Policy query " + retryInterval + "ms before retrying ...");
+ // wait for a while and try to connect to DCAE again
+ Thread.sleep(retryInterval);
+ }
+ }
+ return "";
+ }
+}
diff --git a/src/main/java/org/onap/clamp/clds/config/ClampProperties.java b/src/main/java/org/onap/clamp/clds/config/ClampProperties.java
index 9905585d3..8eae9066d 100644
--- a/src/main/java/org/onap/clamp/clds/config/ClampProperties.java
+++ b/src/main/java/org/onap/clamp/clds/config/ClampProperties.java
@@ -23,13 +23,11 @@
package org.onap.clamp.clds.config;
-import com.google.common.base.Splitter;
-
import com.google.gson.JsonElement;
+
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
-import java.util.List;
import org.apache.commons.io.IOUtils;
import org.onap.clamp.clds.util.JsonUtils;
@@ -53,8 +51,7 @@ public class ClampProperties {
/**
* get property value.
*
- * @param key
- * The first key
+ * @param key The first key
* @return The string with the value
*/
public String getStringValue(String key) {
@@ -65,10 +62,8 @@ public class ClampProperties {
* get property value for a combo key (key1 + "." + key2). If not found just use
* key1.
*
- * @param key1
- * The first key
- * @param key2
- * The second key after a dot
+ * @param key1 The first key
+ * @param key2 The second key after a dot
* @return The string with the value
*/
public String getStringValue(String key1, String key2) {
@@ -83,17 +78,15 @@ public class ClampProperties {
* Return json as objects that can be updated. The value obtained from the
* clds-reference file will be used as a filename.
*
- * @param key
- * The key that will be used to access the clds-reference file
+ * @param key The key that will be used to access the clds-reference file
* @return A jsonNode
- * @throws IOException
- * In case of issues with the JSON parser
+ * @throws IOException In case of issues with the JSON parser
*/
public JsonElement getJsonTemplate(String key) throws IOException {
String fileReference = getStringValue(key);
return (fileReference != null)
- ? JsonUtils.GSON.fromJson(getFileContentFromPath(fileReference), JsonElement.class)
- : null;
+ ? JsonUtils.GSON.fromJson(getFileContentFromPath(fileReference), JsonElement.class)
+ : null;
}
/**
@@ -101,30 +94,25 @@ public class ClampProperties {
* "." + key2), otherwise default to just key1. The value obtained from the
* clds-reference file will be used as a filename.
*
- * @param key1
- * The first key
- * @param key2
- * The second key after a dot
+ * @param key1 The first key
+ * @param key2 The second key after a dot
* @return A JsonNode
- * @throws IOException
- * In case of issues with the JSON parser
+ * @throws IOException In case of issues with the JSON parser
*/
public JsonElement getJsonTemplate(String key1, String key2) throws IOException {
String fileReference = getStringValue(key1, key2);
return (fileReference != null)
- ? JsonUtils.GSON.fromJson(getFileContentFromPath(fileReference), JsonElement.class)
- : null;
+ ? JsonUtils.GSON.fromJson(getFileContentFromPath(fileReference), JsonElement.class)
+ : null;
}
/**
* Return the file content. The value obtained from the clds-reference file will
* be used as a filename.
*
- * @param key
- * The key that will be used to access the clds-reference file
+ * @param key The key that will be used to access the clds-reference file
* @return File content in String
- * @throws IOException
- * In case of issues with the JSON parser
+ * @throws IOException In case of issues with the JSON parser
*/
public String getFileContent(String key) throws IOException {
String fileReference = getStringValue(key);
@@ -136,13 +124,10 @@ public class ClampProperties {
* otherwise default to just key1. The value obtained from the clds-reference
* file will be used as a filename.
*
- * @param key1
- * The first key
- * @param key2
- * The second key after a dot
+ * @param key1 The first key
+ * @param key2 The second key after a dot
* @return File content in String
- * @throws IOException
- * In case of issues with the JSON parser
+ * @throws IOException In case of issues with the JSON parser
*/
public String getFileContent(String key1, String key2) throws IOException {
String fileReference = getStringValue(key1, key2);
@@ -153,18 +138,4 @@ public class ClampProperties {
URL url = appContext.getResource(filepath).getURL();
return IOUtils.toString(url, StandardCharsets.UTF_8);
}
-
- /**
- * Returns the list of strings split with separator.
- *
- * @param key
- * property key
- * @param separator
- * property value separator
- * @return List of Strings split with a separator
- */
- public List<String> getStringList(String key, String separator) {
- return Splitter.on(separator).trimResults().omitEmptyStrings()
- .splitToList(env.getProperty(CONFIG_PREFIX + key));
- }
}
diff --git a/src/main/java/org/onap/clamp/clds/config/PolicyConfiguration.java b/src/main/java/org/onap/clamp/clds/config/PolicyConfiguration.java
deleted file mode 100644
index a4f37e8bb..000000000
--- a/src/main/java/org/onap/clamp/clds/config/PolicyConfiguration.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP CLAMP
- * ================================================================================
- * Copyright (C) 2018 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;
-
-import java.util.Properties;
-
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.stereotype.Component;
-
-@Component
-@ConfigurationProperties(prefix = "clamp.config.policy")
-public class PolicyConfiguration {
-
- public static final String PDP_URL1 = "PDP_URL1";
- public static final String PDP_URL2 = "PDP_URL2";
- public static final String PAP_URL = "PAP_URL";
- public static final String NOTIFICATION_TYPE = "NOTIFICATION_TYPE";
- public static final String NOTIFICATION_UEB_SERVERS = "NOTIFICATION_UEB_SERVERS";
- public static final String CLIENT_ID = "CLIENT_ID";
- public static final String CLIENT_KEY = "CLIENT_KEY";
- public static final String ENVIRONMENT = "ENVIRONMENT";
- private String pdpUrl1;
- private String pdpUrl2;
- private String papUrl;
- private String notificationType;
- private String notificationUebServers;
- private String clientId;
- private String clientKey;
- private String policyEnvironment;
-
- public String getPdpUrl1() {
- return pdpUrl1;
- }
-
- public void setPdpUrl1(String pdpUrl1) {
- this.pdpUrl1 = pdpUrl1;
- }
-
- public String getPdpUrl2() {
- return pdpUrl2;
- }
-
- public void setPdpUrl2(String pdpUrl2) {
- this.pdpUrl2 = pdpUrl2;
- }
-
- public String getPapUrl() {
- return papUrl;
- }
-
- public void setPapUrl(String papUrl) {
- this.papUrl = papUrl;
- }
-
- public String getNotificationType() {
- return notificationType;
- }
-
- public void setNotificationType(String notificationType) {
- this.notificationType = notificationType;
- }
-
- public String getNotificationUebServers() {
- return notificationUebServers;
- }
-
- public void setNotificationUebServers(String notificationUebServers) {
- this.notificationUebServers = notificationUebServers;
- }
-
- public String getClientId() {
- return clientId;
- }
-
- public void setClientId(String clientId) {
- this.clientId = clientId;
- }
-
- public String getClientKey() {
- return clientKey;
- }
-
- public void setClientKey(String clientKey) {
- this.clientKey = clientKey;
- }
-
- public String getPolicyEnvironment() {
- return policyEnvironment;
- }
-
- public void setPolicyEnvironment(String environment) {
- this.policyEnvironment = environment;
- }
-
- /**
- * Returns policy configuration properties.
- *
- * @return policy configuration properties
- */
- public Properties getProperties() {
- Properties prop = new Properties();
- prop.put(PDP_URL1, pdpUrl1);
- prop.put(PDP_URL2, pdpUrl2);
- prop.put(PAP_URL, papUrl);
- prop.put(NOTIFICATION_TYPE, notificationType);
- prop.put(NOTIFICATION_UEB_SERVERS, notificationUebServers);
- prop.put(CLIENT_ID, clientId);
- prop.put(CLIENT_KEY, clientKey);
- prop.put(ENVIRONMENT, policyEnvironment);
- return prop;
- }
-}
diff --git a/src/main/java/org/onap/clamp/clds/config/spring/SdcControllerConfiguration.java b/src/main/java/org/onap/clamp/clds/config/spring/SdcControllerConfiguration.java
index 5a3e22a35..eca45d66f 100644
--- a/src/main/java/org/onap/clamp/clds/config/spring/SdcControllerConfiguration.java
+++ b/src/main/java/org/onap/clamp/clds/config/spring/SdcControllerConfiguration.java
@@ -41,14 +41,12 @@ import org.onap.clamp.loop.CsarInstaller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.Scheduled;
@Configuration
-@ComponentScan(basePackages = { "org.onap.clamp.loop", "org.onap.clamp.clds.config" })
-@Profile("clamp-sdc-controller-new")
+@Profile("clamp-sdc-controller")
public class SdcControllerConfiguration {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcControllerConfiguration.class);
diff --git a/src/main/java/org/onap/clamp/clds/exception/BadRequestException.java b/src/main/java/org/onap/clamp/clds/exception/BadRequestException.java
deleted file mode 100644
index caf525eee..000000000
--- a/src/main/java/org/onap/clamp/clds/exception/BadRequestException.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP CLAMP
- * ================================================================================
- * Copyright (C) 2018 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.exception;
-
-/**
- * New exception to request errors.
- *
- */
-public class BadRequestException extends RuntimeException {
-
- /**
- * The serial version ID.
- */
- private static final long serialVersionUID = -5738167530541646123L;
-
- /**
- * This constructor can be used to create a new CldsConfigException.
- *
- * @param message
- * A string message detailing the problem
- * @param ex
- * The exception sent by the code
- */
- public BadRequestException(String message, Throwable ex) {
- super(message, ex);
- }
-
- /**
- * This constructor can be used to create a new CldsConfigException. Use this
- * constructor only if you are creating a new exception stack, not if an
- * exception was already raised by another code.
- *
- * @param message
- * A string message detailing the problem
- */
- public BadRequestException(String message) {
- super(message);
- }
-
-}
diff --git a/src/main/java/org/onap/clamp/exception/OperationException.java b/src/main/java/org/onap/clamp/clds/exception/sdc/controller/BlueprintParserException.java
index 6e26d294c..7257fd8a0 100644
--- a/src/main/java/org/onap/clamp/exception/OperationException.java
+++ b/src/main/java/org/onap/clamp/clds/exception/sdc/controller/BlueprintParserException.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP CLAMP
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,41 +21,34 @@
*
*/
-package org.onap.clamp.exception;
+package org.onap.clamp.clds.exception.sdc.controller;
/**
- * New exception to CldsUser errors.
- *
+ * Exception during blueprint parsing.
*/
-public class OperationException extends RuntimeException {
+public class BlueprintParserException extends Exception {
/**
- * The serial version ID.
+ * Serial ID.
*/
- private static final long serialVersionUID = 2788967876393519620L;
+ private static final long serialVersionUID = -3044162346353623199L;
/**
- * This constructor can be used to create a new CldsUsersException.
+ * This constructor can be used to create a new SdcDownloadException.
*
- * @param message
- * A string message detailing the problem
- * @param cause
- * The exception sent by the code
+ * @param message The message to dump
*/
- public OperationException(String message, Throwable cause) {
- super(message, cause);
+ public BlueprintParserException(final String message) {
+ super(message);
}
/**
- * This constructor can be used to create a new CldsUsersException. Use this
- * constructor only if you are creating a new exception stack, not if an
- * exception was already raised by another code.
+ * This constructor can be used to create a new SdcDownloadException.
*
- * @param message
- * A string message detailing the problem
+ * @param message The message to dump
+ * @param cause The Throwable cause object
*/
- public OperationException(String message) {
- super(message);
+ public BlueprintParserException(final String message, final Throwable cause) {
+ super(message, cause);
}
-
}
diff --git a/src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryCache.java b/src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryCache.java
index 19bc23d5e..fc2ca5caa 100644
--- a/src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryCache.java
+++ b/src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryCache.java
@@ -46,7 +46,7 @@ public class DcaeInventoryCache {
public void addDcaeInventoryResponse(DcaeInventoryResponse inventoryResponse) {
Set<DcaeInventoryResponse> responsesSet = blueprintsMap.get(inventoryResponse.getAsdcServiceId());
if (responsesSet == null) {
- responsesSet = new TreeSet<DcaeInventoryResponse>();
+ responsesSet = new TreeSet<>();
blueprintsMap.put(inventoryResponse.getAsdcServiceId(), responsesSet);
}
responsesSet.add(inventoryResponse);
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java b/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java
index bd18baea6..fbb37d525 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java
@@ -33,6 +33,7 @@ import java.util.concurrent.ThreadLocalRandom;
import org.onap.clamp.clds.config.ClampProperties;
import org.onap.clamp.clds.config.sdc.SdcSingleControllerConfiguration;
+import org.onap.clamp.clds.exception.sdc.controller.BlueprintParserException;
import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException;
import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException;
import org.onap.clamp.clds.exception.sdc.controller.SdcControllerException;
@@ -290,6 +291,10 @@ public class SdcSingleController {
sendAllNotificationForCsarHandler(notificationData, csar, NotificationType.DEPLOY,
DistributionStatusEnum.DEPLOY_ERROR, e.getMessage());
Thread.currentThread().interrupt();
+ } catch (BlueprintParserException e) {
+ logger.error("BlueprintParser exception caught during the notification processing", e);
+ sendAllNotificationForCsarHandler(notificationData, csar, NotificationType.DEPLOY,
+ DistributionStatusEnum.DEPLOY_ERROR, e.getMessage());
} catch (RuntimeException e) {
logger.error("Unexpected exception caught during the notification processing", e);
sendAllNotificationForCsarHandler(notificationData, csar, NotificationType.DEPLOY,
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintMicroService.java
index 68ac842cf..e00ce9430 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintMicroService.java
@@ -17,7 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
- * Modifications copyright (c) 2019 AT&T
+ * Modifications copyright (c) 2019-2020 AT&T
* ===================================================================
*
*/
@@ -26,25 +26,24 @@ package org.onap.clamp.clds.sdc.controller.installer;
import java.util.Objects;
-public class MicroService {
+public class BlueprintMicroService {
private final String name;
private final String modelType;
private final String inputFrom;
- private String mappedNameJpa;
+ private final String modelVersion;
/**
* The Micro service constructor.
*
- * @param name The name in String
- * @param modelType The model type
- * @param inputFrom Comes from (single chained)
- * @param mappedNameJpa Name in database
+ * @param name The name in String
+ * @param modelType The model type
+ * @param inputFrom Comes from (single chained)
*/
- public MicroService(String name, String modelType, String inputFrom, String mappedNameJpa) {
+ public BlueprintMicroService(String name, String modelType, String inputFrom, String modelVersion) {
this.name = name;
this.inputFrom = inputFrom;
- this.mappedNameJpa = mappedNameJpa;
this.modelType = modelType;
+ this.modelVersion = modelVersion;
}
public String getName() {
@@ -59,18 +58,19 @@ public class MicroService {
return inputFrom;
}
- @Override
- public String toString() {
- return "MicroService{" + "name='" + name + '\'' + ", modelType='" + modelType + '\'' + ", inputFrom='"
- + inputFrom + '\'' + ", mappedNameJpa='" + mappedNameJpa + '\'' + '}';
- }
-
- public String getMappedNameJpa() {
- return mappedNameJpa;
+ /**
+ * modelVerrsion getter.
+ *
+ * @return the modelVersion
+ */
+ public String getModelVersion() {
+ return modelVersion;
}
- public void setMappedNameJpa(String mappedNameJpa) {
- this.mappedNameJpa = mappedNameJpa;
+ @Override
+ public String toString() {
+ return "MicroService {" + "name='" + name + '\'' + ", modelType='" + modelType + '\'' + ", inputFrom='"
+ + inputFrom + '\'' + ", modelVersion='" + modelVersion + '\'' + '}';
}
@Override
@@ -81,13 +81,13 @@ public class MicroService {
if (obj == null || getClass() != obj.getClass()) {
return false;
}
- MicroService that = (MicroService) obj;
+ BlueprintMicroService that = (BlueprintMicroService) obj;
return name.equals(that.name) && modelType.equals(that.modelType) && inputFrom.equals(that.inputFrom)
- && mappedNameJpa.equals(that.mappedNameJpa);
+ && modelVersion.equals(that.modelVersion);
}
@Override
public int hashCode() {
- return Objects.hash(name, modelType, inputFrom, mappedNameJpa);
+ return Objects.hash(name, modelType, inputFrom, modelVersion);
}
}
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 0dd231f03..981a20416 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
@@ -24,6 +24,8 @@
package org.onap.clamp.clds.sdc.controller.installer;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
@@ -38,76 +40,74 @@ import java.util.Map.Entry;
import java.util.Set;
import org.json.JSONObject;
-import org.springframework.stereotype.Component;
+import org.onap.clamp.clds.exception.sdc.controller.BlueprintParserException;
import org.yaml.snakeyaml.Yaml;
-@Component
public class BlueprintParser {
static final String TCA = "TCA";
- static final String HOLMES = "Holmes";
- private static final String TCA_POLICY = "tca_policy";
- private static final String HOLMES_PREFIX = "holmes";
private static final String NODE_TEMPLATES = "node_templates";
private static final String DCAE_NODES = "dcae.nodes.";
+ private static final String DCAE_NODES_POLICY = "dcae.nodes.policy";
private static final String TYPE = "type";
private static final String PROPERTIES = "properties";
private static final String NAME = "name";
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 POLICY_MODEL_ID = "policy_model_id";
+ private static final String POLICY_MODEL_VERSION = "policy_model_version";
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 static final String DEFAULT_VERSION = "1.0.0";
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(BlueprintParser.class);
+
+ private BlueprintParser() {
+
+ }
/**
* Get all micro services from blueprint.
*
* @param blueprintString the blueprint in a String
* @return A set of MircoService
+ * @throws BlueprintParserException In case of issues with the parsing
*/
- public Set<MicroService> getMicroServices(String blueprintString) {
- Set<MicroService> microServices = new HashSet<>();
+ public static Set<BlueprintMicroService> getMicroServices(String blueprintString) throws BlueprintParserException {
+ Set<BlueprintMicroService> microServices = new HashSet<>();
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, inputList);
- microServices.add(microService);
+ if (!nodeTemplate.get(TYPE).getAsString().contains(DCAE_NODES_POLICY)
+ && nodeTemplate.get(TYPE).getAsString().contains(DCAE_NODES)) {
+ BlueprintMicroService microService = getNodeRepresentation(entry, nodeTemplateList, inputList);
+ if (!microService.getModelType().isBlank()) {
+ microServices.add(microService);
+ } else {
+ logger.warn("Microservice " + microService.getName()
+ + " will NOT be used by CLAMP as the model type is not defined or has not been found");
+ }
}
}
- microServices.removeIf(ms -> TCA_POLICY.equals(ms.getName()));
+ logger.debug("Those microservices have been found in the blueprint:" + microServices);
return microServices;
}
/**
- * Does a fallback to TCA or Holmes.
+ * Does a fallback to TCA.
*
- * @param blueprintString the blueprint in a String
* @return The list of microservices
*/
- public List<MicroService> fallbackToOneMicroService(String blueprintString) {
- JsonObject jsonObject = BlueprintParser.convertToJson(blueprintString);
- JsonObject results = jsonObject.get(NODE_TEMPLATES).getAsJsonObject();
- String theBiggestMicroServiceContent = "";
- String theBiggestMicroServiceKey = "";
- for (Entry<String, JsonElement> entry : results.entrySet()) {
- String msAsString = entry.getValue().toString();
- int len = msAsString.length();
- if (len > theBiggestMicroServiceContent.length()) {
- theBiggestMicroServiceContent = msAsString;
- theBiggestMicroServiceKey = entry.getKey();
- }
- }
- String msName = theBiggestMicroServiceKey.toLowerCase().contains(HOLMES_PREFIX) ? HOLMES : TCA;
- return Collections
- .singletonList(new MicroService(msName, "onap.policies.monitoring.cdap.tca.hi.lo.app", "", ""));
+ public static List<BlueprintMicroService> fallbackToOneMicroService() {
+ return Collections.singletonList(
+ new BlueprintMicroService(TCA, "onap.policies.monitoring.cdap.tca.hi.lo.app", "", DEFAULT_VERSION));
}
- String getName(Entry<String, JsonElement> entry) {
+ static String getName(Entry<String, JsonElement> entry) {
String microServiceYamlName = entry.getKey();
JsonObject ob = entry.getValue().getAsJsonObject();
if (ob.has(PROPERTIES)) {
@@ -119,7 +119,7 @@ public class BlueprintParser {
return microServiceYamlName;
}
- String getInput(Entry<String, JsonElement> entry) {
+ static String getInput(Entry<String, JsonElement> entry) {
JsonObject ob = entry.getValue().getAsJsonObject();
if (ob.has(RELATIONSHIPS)) {
JsonArray relationships = ob.getAsJsonArray(RELATIONSHIPS);
@@ -133,51 +133,81 @@ public class BlueprintParser {
return "";
}
- 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, inputList);
- if (!modelType.isEmpty()) {
- return modelType;
+ static String findPropertyInRelationshipsArray(String propertyName, JsonArray relationshipsArray,
+ JsonObject blueprintNodeTemplateList, JsonObject blueprintInputList) throws BlueprintParserException {
+ for (JsonElement elem : relationshipsArray) {
+ if (blueprintNodeTemplateList.get(elem.getAsJsonObject().get(TARGET).getAsString()) == null) {
+ throw new BlueprintParserException(
+ "The Target mentioned in the blueprint is not a known entry in the blueprint: "
+ + elem.getAsJsonObject().get(TARGET).getAsString());
+ } else {
+ String property = getPropertyValue(propertyName,
+ new AbstractMap.SimpleEntry<String, JsonElement>(
+ elem.getAsJsonObject().get(TARGET).getAsString(), blueprintNodeTemplateList
+ .get(elem.getAsJsonObject().get(TARGET).getAsString()).getAsJsonObject()),
+ blueprintNodeTemplateList, blueprintInputList);
+ if (!property.isEmpty()) {
+ return property;
+ }
}
}
return "";
}
- String getModelType(Entry<String, JsonElement> entry, JsonObject nodeTemplateList, JsonObject inputList) {
- JsonObject ob = entry.getValue().getAsJsonObject();
+ static String getDirectOrInputPropertyValue(String propertyName, JsonObject blueprintInputList,
+ JsonObject nodeTemplateContent) {
+ JsonObject properties = nodeTemplateContent.get(PROPERTIES).getAsJsonObject();
+ if (properties.has(propertyName)) {
+ if (properties.get(propertyName).isJsonObject()) {
+ // it's a blueprint parameter
+ return blueprintInputList
+ .get(properties.get(propertyName).getAsJsonObject().get(GET_INPUT).getAsString())
+ .getAsJsonObject().get("default").getAsString();
+ } else {
+ // It's a direct value
+ return properties.get(propertyName).getAsString();
+ }
+ }
+ return "";
+ }
+
+ static String getPropertyValue(String propertyName, Entry<String, JsonElement> nodeTemplateEntry,
+ JsonObject blueprintNodeTemplateList, JsonObject blueprintIputList) throws BlueprintParserException {
+ JsonObject nodeTemplateContent = nodeTemplateEntry.getValue().getAsJsonObject();
// Search first in this node template
- if (ob.has(PROPERTIES)) {
- JsonObject properties = ob.get(PROPERTIES).getAsJsonObject();
- 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();
- }
+ if (nodeTemplateContent.has(PROPERTIES)) {
+ String propValue = getDirectOrInputPropertyValue(propertyName, blueprintIputList, nodeTemplateContent);
+ if (!propValue.isBlank()) {
+ return propValue;
}
}
// Or it's may be defined in a relationship
- if (ob.has(RELATIONSHIPS)) {
- return findModelTypeInTargetArray(ob.get(RELATIONSHIPS).getAsJsonArray(), nodeTemplateList, inputList);
+ if (nodeTemplateContent.has(RELATIONSHIPS)) {
+ return findPropertyInRelationshipsArray(propertyName,
+ nodeTemplateContent.get(RELATIONSHIPS).getAsJsonArray(), blueprintNodeTemplateList,
+ blueprintIputList);
}
return "";
}
- MicroService getNodeRepresentation(Entry<String, JsonElement> entry, JsonObject nodeTemplateList,
- JsonObject inputList) {
- String name = getName(entry);
- String getInputFrom = getInput(entry);
- String modelType = getModelType(entry, nodeTemplateList, inputList);
- return new MicroService(name, modelType, getInputFrom, "");
+ static BlueprintMicroService getNodeRepresentation(Entry<String, JsonElement> nodeTemplateEntry,
+ JsonObject blueprintNodeTemplateList, JsonObject blueprintInputList) throws BlueprintParserException {
+ String modelIdFound = getPropertyValue(POLICY_MODEL_ID, nodeTemplateEntry, blueprintNodeTemplateList,
+ blueprintInputList);
+ String versionFound = getPropertyValue(POLICY_MODEL_VERSION, nodeTemplateEntry, blueprintNodeTemplateList,
+ blueprintInputList);
+ if (modelIdFound.isBlank()) {
+ logger.warn("policy_model_id is not defined for the node template:" + nodeTemplateEntry.getKey());
+ }
+ if (versionFound.isBlank()) {
+ logger.warn("policy_model_version is not defined (setting it to a default value) for the node template:"
+ + nodeTemplateEntry.getKey());
+ }
+ return new BlueprintMicroService(getName(nodeTemplateEntry), modelIdFound, getInput(nodeTemplateEntry),
+ !versionFound.isBlank() ? versionFound : DEFAULT_VERSION);
}
- private String getTarget(JsonObject elementObject) {
+ private static String getTarget(JsonObject elementObject) {
if (elementObject.has(TYPE) && elementObject.has(TARGET)
&& elementObject.get(TYPE).getAsString().equals(CLAMP_NODE_RELATIONSHIPS_GETS_INPUT_FROM)) {
return elementObject.get(TARGET).getAsString();
@@ -186,10 +216,7 @@ public class BlueprintParser {
}
private static JsonObject convertToJson(String yamlString) {
- Yaml yaml = new Yaml();
- Map<String, Object> map = yaml.load(yamlString);
-
- JSONObject jsonObject = new JSONObject(map);
- return new Gson().fromJson(jsonObject.toString(), JsonObject.class);
+ Map<String, Object> map = new Yaml().load(yamlString);
+ return new Gson().fromJson(new JSONObject(map).toString(), JsonObject.class);
}
}
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/ChainGenerator.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/ChainGenerator.java
index 9e76cc938..2bd259c2b 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/ChainGenerator.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/ChainGenerator.java
@@ -42,11 +42,11 @@ public class ChainGenerator {
* @param input A set of microservices
* @return The list of microservice chained
*/
- public List<MicroService> getChainOfMicroServices(Set<MicroService> input) {
- LinkedList<MicroService> returnList = new LinkedList<>();
+ public List<BlueprintMicroService> getChainOfMicroServices(Set<BlueprintMicroService> input) {
+ LinkedList<BlueprintMicroService> returnList = new LinkedList<>();
if (preValidate(input)) {
- LinkedList<MicroService> theList = new LinkedList<>();
- for (MicroService ms : input) {
+ LinkedList<BlueprintMicroService> theList = new LinkedList<>();
+ for (BlueprintMicroService ms : input) {
insertNodeTemplateIntoChain(ms, theList);
}
if (postValidate(theList)) {
@@ -56,16 +56,16 @@ public class ChainGenerator {
return returnList;
}
- private boolean preValidate(Set<MicroService> input) {
- List<MicroService> noInputs = input.stream().filter(ms -> "".equals(ms.getInputFrom()))
+ private boolean preValidate(Set<BlueprintMicroService> input) {
+ List<BlueprintMicroService> noInputs = input.stream().filter(ms -> "".equals(ms.getInputFrom()))
.collect(Collectors.toList());
return noInputs.size() == 1;
}
- private boolean postValidate(LinkedList<MicroService> microServices) {
+ private boolean postValidate(LinkedList<BlueprintMicroService> microServices) {
for (int i = 1; i < microServices.size() - 1; i++) {
- MicroService prev = microServices.get(i - 1);
- MicroService current = microServices.get(i);
+ BlueprintMicroService prev = microServices.get(i - 1);
+ BlueprintMicroService current = microServices.get(i);
if (!current.getInputFrom().equals(prev.getName())) {
return false;
}
@@ -73,11 +73,11 @@ public class ChainGenerator {
return true;
}
- private void insertNodeTemplateIntoChain(MicroService microServicetoInsert,
- LinkedList<MicroService> chainOfMicroServices) {
+ private void insertNodeTemplateIntoChain(BlueprintMicroService microServicetoInsert,
+ LinkedList<BlueprintMicroService> chainOfMicroServices) {
int insertIndex = 0;
for (int i = 0; i < chainOfMicroServices.size(); i++) {
- MicroService current = chainOfMicroServices.get(i);
+ BlueprintMicroService current = chainOfMicroServices.get(i);
if (microServicetoInsert.getName().equals(current.getInputFrom())) {
insertIndex = i;
break;
diff --git a/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java b/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java
index 8ded0cb87..6ce89873b 100755
--- a/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java
+++ b/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java
@@ -28,12 +28,12 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
-import org.onap.clamp.clds.sdc.controller.installer.MicroService;
+import org.onap.clamp.clds.sdc.controller.installer.BlueprintMicroService;
public class ClampGraphBuilder {
private String policy;
private String collector;
- private List<MicroService> microServices = new ArrayList<>();
+ private List<BlueprintMicroService> microServices = new ArrayList<>();
private final Painter painter;
public ClampGraphBuilder(Painter painter) {
@@ -50,12 +50,12 @@ public class ClampGraphBuilder {
return this;
}
- public ClampGraphBuilder addMicroService(MicroService ms) {
+ public ClampGraphBuilder addMicroService(BlueprintMicroService ms) {
microServices.add(ms);
return this;
}
- public ClampGraphBuilder addAllMicroServices(List<MicroService> msList) {
+ public ClampGraphBuilder addAllMicroServices(List<BlueprintMicroService> msList) {
microServices.addAll(msList);
return this;
}
diff --git a/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java b/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java
index af6caf932..d96c9e537 100755
--- a/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java
+++ b/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java
@@ -31,7 +31,7 @@ import java.awt.RenderingHints;
import java.util.List;
import org.apache.batik.svggen.SVGGraphics2D;
-import org.onap.clamp.clds.sdc.controller.installer.MicroService;
+import org.onap.clamp.clds.sdc.controller.installer.BlueprintMicroService;
public class Painter {
private final int canvasSize;
@@ -57,7 +57,7 @@ public class Painter {
this.canvasSize = DEFALUT_CANVAS_SIZE;
}
- DocumentBuilder doPaint(String collector, List<MicroService> microServices, String policy) {
+ DocumentBuilder doPaint(String collector, List<BlueprintMicroService> microServices, String policy) {
int numOfRectangles = 2 + microServices.size();
int numOfArrows = numOfRectangles + 1;
int baseLength = (canvasSize - 2 * CIRCLE_RADIUS) / (numOfArrows + numOfRectangles);
@@ -76,12 +76,12 @@ public class Painter {
return ib.getDocumentBuilder();
}
- private void doTheActualDrawing(String collector, List<MicroService> microServices, String policy,
+ private void doTheActualDrawing(String collector, List<BlueprintMicroService> microServices, String policy,
ImageBuilder ib) {
ib.circle("start-circle", SLIM_LINE).arrow().rectangle(collector, RectTypes.COLECTOR, collector);
- for (MicroService ms : microServices) {
- ib.arrow().rectangle(ms.getMappedNameJpa(), RectTypes.MICROSERVICE, ms.getName());
+ for (BlueprintMicroService ms : microServices) {
+ ib.arrow().rectangle(ms.getModelType(), RectTypes.MICROSERVICE, ms.getName());
}
ib.arrow().rectangle(policy, RectTypes.POLICY, policy).arrow().circle("stop-circle", THICK_LINE);
diff --git a/src/main/java/org/onap/clamp/clds/util/drawing/SvgFacade.java b/src/main/java/org/onap/clamp/clds/util/drawing/SvgFacade.java
index ae0c1729c..251f48864 100644
--- a/src/main/java/org/onap/clamp/clds/util/drawing/SvgFacade.java
+++ b/src/main/java/org/onap/clamp/clds/util/drawing/SvgFacade.java
@@ -27,7 +27,7 @@ package org.onap.clamp.clds.util.drawing;
import java.util.List;
import org.apache.batik.svggen.SVGGraphics2D;
-import org.onap.clamp.clds.sdc.controller.installer.MicroService;
+import org.onap.clamp.clds.sdc.controller.installer.BlueprintMicroService;
import org.onap.clamp.clds.util.XmlTools;
import org.springframework.stereotype.Component;
import org.w3c.dom.Document;
@@ -40,7 +40,7 @@ public class SvgFacade {
* @param microServicesChain THe chain of microservices
* @return A String containing the SVG
*/
- public String getSvgImage(List<MicroService> microServicesChain) {
+ public String getSvgImage(List<BlueprintMicroService> microServicesChain) {
SVGGraphics2D svgGraphics2D = new SVGGraphics2D(XmlTools.createEmptySvgDocument());
Document document = XmlTools.createEmptySvgDocument();
DocumentBuilder dp = new DocumentBuilder(document, svgGraphics2D.getDOMFactory());
diff --git a/src/main/java/org/onap/clamp/loop/CsarInstaller.java b/src/main/java/org/onap/clamp/loop/CsarInstaller.java
index 013d3419d..c0cfac960 100644
--- a/src/main/java/org/onap/clamp/loop/CsarInstaller.java
+++ b/src/main/java/org/onap/clamp/loop/CsarInstaller.java
@@ -33,13 +33,15 @@ import java.util.Map.Entry;
import org.json.simple.parser.ParseException;
import org.onap.clamp.clds.client.DcaeInventoryServices;
+import org.onap.clamp.clds.client.PolicyEngineServices;
+import org.onap.clamp.clds.exception.sdc.controller.BlueprintParserException;
import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException;
import org.onap.clamp.clds.model.dcae.DcaeInventoryResponse;
import org.onap.clamp.clds.sdc.controller.installer.BlueprintArtifact;
+import org.onap.clamp.clds.sdc.controller.installer.BlueprintMicroService;
import org.onap.clamp.clds.sdc.controller.installer.BlueprintParser;
import org.onap.clamp.clds.sdc.controller.installer.ChainGenerator;
import org.onap.clamp.clds.sdc.controller.installer.CsarHandler;
-import org.onap.clamp.clds.sdc.controller.installer.MicroService;
import org.onap.clamp.clds.util.drawing.SvgFacade;
import org.onap.clamp.loop.service.CsarServiceInstaller;
import org.onap.clamp.loop.service.Service;
@@ -47,6 +49,8 @@ import org.onap.clamp.loop.template.LoopElementModel;
import org.onap.clamp.loop.template.LoopTemplate;
import org.onap.clamp.loop.template.LoopTemplatesRepository;
import org.onap.clamp.loop.template.PolicyModel;
+import org.onap.clamp.loop.template.PolicyModelId;
+import org.onap.clamp.loop.template.PolicyModelsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
@@ -61,31 +65,27 @@ import org.springframework.stereotype.Component;
public class CsarInstaller {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(CsarInstaller.class);
- public static final String CONTROL_NAME_PREFIX = "ClosedLoop-";
- public static final String GET_INPUT_BLUEPRINT_PARAM = "get_input";
- // This will be used later as the policy scope
- public static final String MODEL_NAME_PREFIX = "Loop_";
@Autowired
- LoopsRepository loopRepository;
+ private PolicyModelsRepository policyModelsRepository;
@Autowired
- LoopTemplatesRepository loopTemplatesRepository;
+ private LoopTemplatesRepository loopTemplatesRepository;
@Autowired
- BlueprintParser blueprintParser;
+ private ChainGenerator chainGenerator;
@Autowired
- ChainGenerator chainGenerator;
+ private DcaeInventoryServices dcaeInventoryService;
@Autowired
- DcaeInventoryServices dcaeInventoryService;
+ private SvgFacade svgFacade;
@Autowired
- private SvgFacade svgFacade;
+ private CsarServiceInstaller csarServiceInstaller;
@Autowired
- CsarServiceInstaller csarServiceInstaller;
+ private PolicyEngineServices policyEngineServices;
/**
* Verify whether Csar is deployed.
@@ -113,8 +113,11 @@ public class CsarInstaller {
* @param csar The Csar Handler
* @throws SdcArtifactInstallerException The SdcArtifactInstallerException
* @throws InterruptedException The InterruptedException
+ * @throws BlueprintParserException In case of issues with the blueprint
+ * parsing
*/
- public void installTheCsar(CsarHandler csar) throws SdcArtifactInstallerException, InterruptedException {
+ public void installTheCsar(CsarHandler csar)
+ throws SdcArtifactInstallerException, InterruptedException, BlueprintParserException {
logger.info("Installing the CSAR " + csar.getFilePath());
installTheLoopTemplates(csar, csarServiceInstaller.installTheService(csar));
logger.info("Successfully installed the CSAR " + csar.getFilePath());
@@ -127,9 +130,11 @@ public class CsarInstaller {
* @param service The service object that is related to the loop
* @throws SdcArtifactInstallerException The SdcArtifactInstallerException
* @throws InterruptedException The InterruptedException
+ * @throws BlueprintParserException In case of issues with the blueprint
+ * parsing
*/
public void installTheLoopTemplates(CsarHandler csar, Service service)
- throws SdcArtifactInstallerException, InterruptedException {
+ throws SdcArtifactInstallerException, InterruptedException, BlueprintParserException {
try {
logger.info("Installing the Loops");
for (Entry<String, BlueprintArtifact> blueprint : csar.getMapOfBlueprints().entrySet()) {
@@ -145,20 +150,20 @@ public class CsarInstaller {
}
private LoopTemplate createLoopTemplateFromBlueprint(CsarHandler csar, BlueprintArtifact blueprintArtifact,
- Service service) throws IOException, ParseException, InterruptedException {
+ Service service) throws IOException, ParseException, InterruptedException, BlueprintParserException {
LoopTemplate newLoopTemplate = new LoopTemplate();
newLoopTemplate.setBlueprint(blueprintArtifact.getDcaeBlueprint());
newLoopTemplate.setName(LoopTemplate.generateLoopTemplateName(csar.getSdcNotification().getServiceName(),
csar.getSdcNotification().getServiceVersion(),
blueprintArtifact.getResourceAttached().getResourceInstanceName(),
blueprintArtifact.getBlueprintArtifactName()));
- List<MicroService> microServicesChain = chainGenerator
- .getChainOfMicroServices(blueprintParser.getMicroServices(blueprintArtifact.getDcaeBlueprint()));
+ List<BlueprintMicroService> microServicesChain = chainGenerator
+ .getChainOfMicroServices(BlueprintParser.getMicroServices(blueprintArtifact.getDcaeBlueprint()));
if (microServicesChain.isEmpty()) {
- microServicesChain = blueprintParser.fallbackToOneMicroService(blueprintArtifact.getDcaeBlueprint());
+ microServicesChain = BlueprintParser.fallbackToOneMicroService();
}
newLoopTemplate.setModelService(service);
- newLoopTemplate.addLoopElementModels(createMicroServiceModels(microServicesChain, csar, blueprintArtifact));
+ newLoopTemplate.addLoopElementModels(createMicroServiceModels(microServicesChain));
newLoopTemplate.setMaximumInstancesAllowed(0);
newLoopTemplate.setSvgRepresentation(svgFacade.getSvgImage(microServicesChain));
DcaeInventoryResponse dcaeResponse = queryDcaeToGetServiceTypeId(blueprintArtifact);
@@ -166,31 +171,26 @@ public class CsarInstaller {
return newLoopTemplate;
}
- private HashSet<LoopElementModel> createMicroServiceModels(List<MicroService> microServicesChain, CsarHandler csar,
- BlueprintArtifact blueprintArtifact) throws IOException {
+ private HashSet<LoopElementModel> createMicroServiceModels(List<BlueprintMicroService> microServicesChain)
+ throws InterruptedException {
HashSet<LoopElementModel> newSet = new HashSet<>();
- for (MicroService microService : microServicesChain) {
+ for (BlueprintMicroService microService : microServicesChain) {
LoopElementModel loopElementModel = new LoopElementModel(microService.getModelType(), "CONFIG_POLICY",
- blueprintArtifact.getDcaeBlueprint());
+ null);
newSet.add(loopElementModel);
- loopElementModel.addPolicyModel(createPolicyModel(microService, csar));
+ loopElementModel.addPolicyModel(getPolicyModel(microService));
}
return newSet;
}
- private static String createPolicyAcronym(String policyType) {
- String[] policyNameArray = policyType.split("\\.");
- return policyNameArray[policyNameArray.length - 1];
- }
-
- private PolicyModel createPolicyModel(MicroService microService, CsarHandler csar) throws IOException {
- return new PolicyModel(microService.getModelType(), csar.getPolicyModelYaml().orElse(""), "1.0",
- createPolicyAcronym(microService.getModelType()));
+ private PolicyModel getPolicyModel(BlueprintMicroService microService) throws InterruptedException {
+ return policyModelsRepository
+ .findById(new PolicyModelId(microService.getModelType(), microService.getModelVersion()))
+ .orElse(policyEngineServices.createPolicyModelFromPolicyEngine(microService));
}
/**
- * ll get the latest version of the artifact (version can be specified to DCAE
- * call).
+ * Get the service blueprint Id in the Dcae inventory using the SDC UUID.
*
* @return The DcaeInventoryResponse object containing the dcae values
*/
diff --git a/src/main/java/org/onap/clamp/loop/Loop.java b/src/main/java/org/onap/clamp/loop/Loop.java
index 339812672..0ac8030d3 100644
--- a/src/main/java/org/onap/clamp/loop/Loop.java
+++ b/src/main/java/org/onap/clamp/loop/Loop.java
@@ -131,7 +131,7 @@ public class Loop extends AuditEntity implements Serializable {
@Expose
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH }, fetch = FetchType.EAGER)
- @JoinColumn(name = "loop_template_name")
+ @JoinColumn(name = "loop_template_name", nullable=false)
private LoopTemplate loopTemplate;
private void initializeExternalComponents() {
@@ -253,10 +253,12 @@ public class Loop extends AuditEntity implements Serializable {
}
public Map<String, ExternalComponent> getComponents() {
+ refreshDcaeComponents();
return components;
}
public ExternalComponent getComponent(String componentName) {
+ refreshDcaeComponents();
return this.components.get(componentName);
}
@@ -272,6 +274,17 @@ public class Loop extends AuditEntity implements Serializable {
this.loopTemplate = loopTemplate;
}
+ private void refreshDcaeComponents() {
+ if (!this.loopTemplate.getUniqueBlueprint()) {
+ this.components.remove("DCAE");
+ for (MicroServicePolicy policy : this.microServicePolicies) {
+ if (!this.components.containsKey("DCAE_" + policy.getName())) {
+ this.addComponent(new DcaeComponent(policy.getName()));
+ }
+ }
+ }
+ }
+
/**
* Generate the loop name.
*
@@ -282,9 +295,9 @@ public class Loop extends AuditEntity implements Serializable {
* @return The generated loop name
*/
public static String generateLoopName(String serviceName, String serviceVersion, String resourceName,
- String blueprintFilename) {
+ String blueprintFileName) {
StringBuilder buffer = new StringBuilder("LOOP_").append(serviceName).append("_v").append(serviceVersion)
- .append("_").append(resourceName).append("_").append(blueprintFilename.replaceAll(".yaml", ""));
+ .append("_").append(resourceName).append("_").append(blueprintFileName.replaceAll(".yaml", ""));
return buffer.toString().replace('.', '_').replaceAll(" ", "");
}
diff --git a/src/main/java/org/onap/clamp/loop/components/external/DcaeComponent.java b/src/main/java/org/onap/clamp/loop/components/external/DcaeComponent.java
index 21960e387..7c0e3ccbb 100644
--- a/src/main/java/org/onap/clamp/loop/components/external/DcaeComponent.java
+++ b/src/main/java/org/onap/clamp/loop/components/external/DcaeComponent.java
@@ -48,6 +48,8 @@ public class DcaeComponent extends ExternalComponent {
private static final String DCAE_SERVICETYPE_ID = "serviceTypeId";
private static final String DCAE_INPUTS = "inputs";
+ private String name;
+
public static final ExternalComponentState BLUEPRINT_DEPLOYED = new ExternalComponentState("BLUEPRINT_DEPLOYED",
"The DCAE blueprint has been found in the DCAE inventory but not yet instancianted for this loop");
public static final ExternalComponentState PROCESSING_MICROSERVICE_INSTALLATION = new ExternalComponentState(
@@ -73,13 +75,20 @@ public class DcaeComponent extends ExternalComponent {
public DcaeComponent() {
super(BLUEPRINT_DEPLOYED);
+ this.name = "DCAE";
+ }
+
+ public DcaeComponent(String name) {
+ super(BLUEPRINT_DEPLOYED);
+ this.name = "DCAE_" + name;
}
@Override
public String getComponentName() {
- return "DCAE";
+ return name;
}
+
/**
* Convert the json response to a DcaeOperationStatusResponse.
*
@@ -170,7 +179,7 @@ public class DcaeComponent extends ExternalComponent {
/**
* Return the uninstallation payload for DCAE.
*
- * @param microServicePolicy The microServicePolicy object
+ * @param policy The microServicePolicy object
* @return The payload in string (json)
*/
public static String getUndeployPayload(MicroServicePolicy policy) {
diff --git a/src/main/java/org/onap/clamp/loop/template/LoopElementModel.java b/src/main/java/org/onap/clamp/loop/template/LoopElementModel.java
index e3f05a01d..0a0831bb7 100644
--- a/src/main/java/org/onap/clamp/loop/template/LoopElementModel.java
+++ b/src/main/java/org/onap/clamp/loop/template/LoopElementModel.java
@@ -70,7 +70,7 @@ public class LoopElementModel extends AuditEntity implements Serializable {
/**
* Here we store the blueprint coming from DCAE.
*/
- @Column(columnDefinition = "MEDIUMTEXT", nullable = false, name = "blueprint_yaml")
+ @Column(columnDefinition = "MEDIUMTEXT", name = "blueprint_yaml")
private String blueprint;
/**
diff --git a/src/main/java/org/onap/clamp/loop/template/LoopTemplate.java b/src/main/java/org/onap/clamp/loop/template/LoopTemplate.java
index b8adebae9..3e90c1e5b 100644
--- a/src/main/java/org/onap/clamp/loop/template/LoopTemplate.java
+++ b/src/main/java/org/onap/clamp/loop/template/LoopTemplate.java
@@ -70,7 +70,6 @@ public class LoopTemplate extends AuditEntity implements Serializable {
@Column(columnDefinition = "MEDIUMTEXT", name = "blueprint_yaml")
private String blueprint;
- @Expose
@Column(columnDefinition = "MEDIUMTEXT", name = "svg_representation")
private String svgRepresentation;
@@ -88,6 +87,10 @@ public class LoopTemplate extends AuditEntity implements Serializable {
@Column(name = "maximum_instances_allowed")
private Integer maximumInstancesAllowed;
+ @Expose
+ @Column(name = "unique_blueprint", columnDefinition = "boolean default false")
+ private boolean uniqueBlueprint;
+
/**
* name getter.
*
@@ -140,6 +143,11 @@ public class LoopTemplate extends AuditEntity implements Serializable {
*/
public void setBlueprint(String blueprint) {
this.blueprint = blueprint;
+ if (blueprint == null) {
+ this.uniqueBlueprint = false;
+ } else {
+ this.uniqueBlueprint = true;
+ }
}
/**
@@ -245,6 +253,15 @@ public class LoopTemplate extends AuditEntity implements Serializable {
}
/**
+ * uniqueBlueprint getter.
+ *
+ * @return the uniqueBlueprint
+ */
+ public boolean getUniqueBlueprint() {
+ return uniqueBlueprint;
+ }
+
+ /**
* Default constructor for serialization.
*/
public LoopTemplate() {
@@ -265,7 +282,7 @@ public class LoopTemplate extends AuditEntity implements Serializable {
public LoopTemplate(String name, String blueprint, String svgRepresentation, Integer maxInstancesAllowed,
Service service) {
this.name = name;
- this.blueprint = blueprint;
+ this.setBlueprint(blueprint);
this.svgRepresentation = svgRepresentation;
this.maximumInstancesAllowed = maxInstancesAllowed;
@@ -312,10 +329,10 @@ public class LoopTemplate extends AuditEntity implements Serializable {
* @return The generated loop template name
*/
public static String generateLoopTemplateName(String serviceName, String serviceVersion, String resourceName,
- String blueprintFilename) {
+ String blueprintFileName) {
StringBuilder buffer = new StringBuilder("LOOP_TEMPLATE_").append(serviceName).append("_v")
.append(serviceVersion).append("_").append(resourceName).append("_")
- .append(blueprintFilename.replaceAll(".yaml", ""));
+ .append(blueprintFileName.replaceAll(".yaml", ""));
return buffer.toString().replace('.', '_').replaceAll(" ", "");
}
}
diff --git a/src/main/java/org/onap/clamp/loop/template/PolicyModel.java b/src/main/java/org/onap/clamp/loop/template/PolicyModel.java
index 886e8c806..53539fccb 100644
--- a/src/main/java/org/onap/clamp/loop/template/PolicyModel.java
+++ b/src/main/java/org/onap/clamp/loop/template/PolicyModel.java
@@ -224,7 +224,13 @@ public class PolicyModel extends AuditEntity implements Serializable, Comparable
@Override
public int compareTo(PolicyModel arg0) {
- // Reverse it, so that by default we have the latest
- return SemanticVersioning.compare(arg0.getVersion(), this.version);
+
+ if (this.getPolicyModelType().equals(arg0.getPolicyModelType())) {
+ // Reverse it, so that by default we have the latest in they are same model type
+ return SemanticVersioning.compare(arg0.getVersion(), this.version);
+ } else {
+ return this.getPolicyModelType().compareTo(arg0.getPolicyModelType());
+ }
+
}
}
diff --git a/src/main/java/org/onap/clamp/policy/downloader/PolicyDownloader.java b/src/main/java/org/onap/clamp/policy/downloader/PolicyDownloader.java
new file mode 100644
index 000000000..8795a1257
--- /dev/null
+++ b/src/main/java/org/onap/clamp/policy/downloader/PolicyDownloader.java
@@ -0,0 +1,96 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2020 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.policy.downloader;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+import java.util.LinkedHashMap;
+import java.util.Map.Entry;
+
+import org.onap.clamp.clds.client.PolicyEngineServices;
+import org.onap.clamp.loop.template.PolicyModel;
+import org.onap.clamp.loop.template.PolicyModelId;
+import org.onap.clamp.loop.template.PolicyModelsRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.yaml.snakeyaml.Yaml;
+
+/**
+ * This class implements a periodic job that is done in the background to
+ * synchronize policy models available on the policy engine and the clamp
+ * database table PolicyModel.
+ */
+@Configuration
+@Profile("clamp-policy-controller")
+public class PolicyDownloader {
+
+ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyDownloader.class);
+ protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
+ protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
+ public static final String POLICY_RETRY_INTERVAL = "policy.retry.interval";
+ public static final String POLICY_RETRY_LIMIT = "policy.retry.limit";
+
+ private final PolicyEngineServices policyEngineServices;
+ private final PolicyModelsRepository policyModelsRepository;
+
+ @Autowired
+ public PolicyDownloader(PolicyEngineServices policyEngineService, PolicyModelsRepository policyModelsRepository) {
+ this.policyEngineServices = policyEngineService;
+ this.policyModelsRepository = policyModelsRepository;
+ }
+
+ private void createPolicyInDbIfNeeded(PolicyModel policyModel) {
+ if (!policyModelsRepository
+ .existsById(new PolicyModelId(policyModel.getPolicyModelType(), policyModel.getVersion()))) {
+ policyModelsRepository.save(policyModel);
+ }
+ }
+
+ @Scheduled(fixedRate = 120000)
+ public void synchronizeAllPolicies() throws InterruptedException {
+ try {
+ LinkedHashMap<String, Object> loadedYaml = new Yaml().load(policyEngineServices.downloadAllPolicies());
+ if (loadedYaml == null || loadedYaml.isEmpty()) {
+ logger.warn(
+ "getAllPolicyType yaml returned by policy engine could not be decoded, as it's null or empty");
+ return;
+ }
+
+ LinkedHashMap<String, Object> policyTypesList = (LinkedHashMap<String, Object>) loadedYaml
+ .get("policy_types");
+ for (Entry<String, Object> policyType : policyTypesList.entrySet()) {
+ createPolicyInDbIfNeeded(policyEngineServices.createPolicyModelFromPolicyEngine(policyType.getKey(),
+ ((String) ((LinkedHashMap<String, Object>) policyType.getValue()).get("version"))));
+ }
+ } catch (InterruptedException e) {
+ logger.warn("query to policy engine has been interrupted", e);
+ throw e;
+ }
+
+ }
+
+}