aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2020-02-03 20:27:59 +0100
committersebdet <sebastien.determe@intl.att.com>2020-02-10 17:57:30 +0100
commit5d03e8b55ff7780079085184f6d30a4d0a26a4a7 (patch)
treef15abb7d36fe215b4b800278a4a9a2c541799b1c /src/main/java/org/onap
parentb398c32d092ca7ca14fa37d22fae6cbc1710e66e (diff)
Get policy in CsarInstaller
Get the policies on the PEF engine when installing the CSAR (if needed) Issue-ID: CLAMP-518 Change-Id: I2cca157821c22ef63dc748984140287667cc4663 Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src/main/java/org/onap')
-rw-r--r--src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java110
-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/sdc/controller/BlueprintParserException.java54
-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.java69
-rw-r--r--src/main/java/org/onap/clamp/loop/template/LoopElementModel.java2
-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.java61
17 files changed, 438 insertions, 328 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..d99e9b569
--- /dev/null
+++ b/src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java
@@ -0,0 +1,110 @@
+/*-
+ * ============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.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 final ClampProperties refProp;
+
+ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyEngineServices.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";
+
+ @Autowired
+ public PolicyEngineServices(CamelContext camelContext, ClampProperties refProp) {
+ this.refProp = refProp;
+ this.camelContext = camelContext;
+ }
+
+ private void downloadAllPolicies() {
+ /*
+ * Exchange myCamelExchange = ExchangeBuilder.anExchange(camelContext)
+ * .withProperty("blueprintResourceId",
+ * resourceUuid).withProperty("blueprintServiceId", serviceUuid)
+ * .withProperty("blueprintName", artifactName).build();
+ * metricsLogger.info("Attempt n°" + i + " to contact DCAE inventory");
+ *
+ * Exchange exchangeResponse =
+ * camelContext.createProducerTemplate().send("direct:get-all-policy-models",
+ * myCamelExchange);
+ */
+ }
+
+ /**
+ * 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 {
+ int retryInterval = 0;
+ int retryLimit = 1;
+ 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));
+ }
+ for (int i = 0; i < retryLimit; i++) {
+ Exchange paramExchange = ExchangeBuilder.anExchange(camelContext)
+ .withProperty("policyModelName", policyType).withProperty("policyModelVersion", policyVersion)
+ .build();
+
+ Exchange exchangeResponse = camelContext.createProducerTemplate().send("direct:get-policy-model",
+ paramExchange);
+
+ if (Integer.valueOf(200).equals(exchangeResponse.getIn().getHeader("CamelHttpResponseCode"))) {
+ return (String) exchangeResponse.getIn().getBody();
+ } else {
+ logger.info("Policy " + 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/sdc/controller/BlueprintParserException.java b/src/main/java/org/onap/clamp/clds/exception/sdc/controller/BlueprintParserException.java
new file mode 100644
index 000000000..7257fd8a0
--- /dev/null
+++ b/src/main/java/org/onap/clamp/clds/exception/sdc/controller/BlueprintParserException.java
@@ -0,0 +1,54 @@
+/*-
+ * ============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.exception.sdc.controller;
+
+/**
+ * Exception during blueprint parsing.
+ */
+public class BlueprintParserException extends Exception {
+
+ /**
+ * Serial ID.
+ */
+ private static final long serialVersionUID = -3044162346353623199L;
+
+ /**
+ * This constructor can be used to create a new SdcDownloadException.
+ *
+ * @param message The message to dump
+ */
+ public BlueprintParserException(final String message) {
+ super(message);
+ }
+
+ /**
+ * This constructor can be used to create a new SdcDownloadException.
+ *
+ * @param message The message to dump
+ * @param cause The Throwable cause object
+ */
+ 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..022b0e28a 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,14 +171,14 @@ 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;
}
@@ -183,14 +188,20 @@ public class CsarInstaller {
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 createPolicyModel(BlueprintMicroService microService) throws InterruptedException {
+ return new PolicyModel(microService.getModelType(),
+ policyEngineServices.downloadOnePolicy(microService.getModelType(), microService.getModelVersion()),
+ microService.getModelVersion(), createPolicyAcronym(microService.getModelType()));
+ }
+
+ private PolicyModel getPolicyModel(BlueprintMicroService microService) throws InterruptedException {
+ return policyModelsRepository
+ .findById(new PolicyModelId(microService.getModelType(), microService.getModelVersion()))
+ .orElse(createPolicyModel(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/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/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..b712dc3f6
--- /dev/null
+++ b/src/main/java/org/onap/clamp/policy/downloader/PolicyDownloader.java
@@ -0,0 +1,61 @@
+/*-
+ * ============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 org.apache.camel.CamelContext;
+import org.onap.clamp.clds.client.DcaeInventoryServices;
+import org.onap.clamp.clds.config.ClampProperties;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
+
+/**
+ * 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(DcaeInventoryServices.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 CamelContext camelContext;
+
+ private final ClampProperties refProp;
+
+ @Autowired
+ public PolicyDownloader(CamelContext camelContext, ClampProperties refProp) {
+ this.refProp = refProp;
+ this.camelContext = camelContext;
+ }
+
+}