aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorDeterme, Sebastien (sd378r) <sd378r@intl.att.com>2018-04-30 15:15:39 +0200
committerDeterme, Sebastien (sd378r) <sd378r@intl.att.com>2018-04-30 15:15:39 +0200
commit269d207cee2ec47b2ecf1830e46ac45b7cea38f2 (patch)
treec74324ae14ede57abd25fee8211ad4de1e29d78b /src/main/java
parent880a4ae41cfb06d43fa0a0d0b86f358c965534b7 (diff)
Fix Sdc Controller
Fix the policy_id sent autogenerated for DCAE deployment, this is now done at submit time Issue-ID: CLAMP-151,CLAMP-153 Change-Id: I1b0e8bb1953a30cc96a9ca0829ff8d5739308573 Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/onap/clamp/clds/client/CldsEventDelegate.java15
-rw-r--r--src/main/java/org/onap/clamp/clds/model/properties/ModelProperties.java20
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java69
3 files changed, 71 insertions, 33 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/CldsEventDelegate.java b/src/main/java/org/onap/clamp/clds/client/CldsEventDelegate.java
index b1243dc2..ce2169fc 100644
--- a/src/main/java/org/onap/clamp/clds/client/CldsEventDelegate.java
+++ b/src/main/java/org/onap/clamp/clds/client/CldsEventDelegate.java
@@ -28,8 +28,11 @@ import com.att.eelf.configuration.EELFManager;
import org.apache.camel.Exchange;
import org.apache.camel.Handler;
+import org.onap.clamp.clds.config.ClampProperties;
import org.onap.clamp.clds.dao.CldsDao;
import org.onap.clamp.clds.model.CldsEvent;
+import org.onap.clamp.clds.model.CldsModel;
+import org.onap.clamp.clds.model.properties.ModelProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -43,6 +46,8 @@ public class CldsEventDelegate {
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
@Autowired
private CldsDao cldsDao;
+ @Autowired
+ private ClampProperties refProp;
/**
* Insert event using process variables.
@@ -65,5 +70,15 @@ public class CldsEventDelegate {
// won't really have userid here...
CldsEvent.insEvent(cldsDao, controlName, userid, actionCd, actionStateCd, camelExchange.getExchangeId());
}
+ generateAutoPolicyId(camelExchange);
+ }
+
+ private void generateAutoPolicyId(Exchange camelExchange) {
+ ModelProperties prop = ModelProperties.create(camelExchange);
+ ;
+ CldsModel cldsModel = CldsModel.retrieve(cldsDao, (String) camelExchange.getProperty("modelName"), false);
+ cldsModel.setPropText(cldsModel.getPropText().replaceAll("AUTO_GENERATED_POLICY_ID_AT_SUBMIT",
+ prop.getPolicyNameForDcaeDeploy(refProp)));
+ cldsModel.save(cldsDao, (String) camelExchange.getProperty("userid"));
}
}
diff --git a/src/main/java/org/onap/clamp/clds/model/properties/ModelProperties.java b/src/main/java/org/onap/clamp/clds/model/properties/ModelProperties.java
index 5b002e71..d5f3ae22 100644
--- a/src/main/java/org/onap/clamp/clds/model/properties/ModelProperties.java
+++ b/src/main/java/org/onap/clamp/clds/model/properties/ModelProperties.java
@@ -217,11 +217,15 @@ public class ModelProperties {
return normalizePolicyScopeName(controlName + "_" + currentModelElementId);
}
+ private String createScopeSeparator(String policyScope) {
+ return policyScope.contains(".") ? "" : ".";
+ }
+
/**
* @return the currentPolicyScopeAndPolicyName
*/
public String getCurrentPolicyScopeAndPolicyName() {
- return normalizePolicyScopeName(modelName + "." + getCurrentPolicyName());
+ return normalizePolicyScopeName(modelName + createScopeSeparator(modelName) + getCurrentPolicyName());
}
/**
@@ -229,7 +233,7 @@ public class ModelProperties {
* deploy
*/
public String getPolicyNameForDcaeDeploy(ClampProperties refProp) {
- return normalizePolicyScopeName(modelName + "."
+ return normalizePolicyScopeName(modelName + createScopeSeparator(modelName)
+ refProp.getStringValue(PolicyClient.POLICY_MS_NAME_PREFIX_PROPERTY_NAME) + getCurrentPolicyName());
}
@@ -237,22 +241,16 @@ public class ModelProperties {
* @return the policyScopeAndNameWithUniqueId
*/
public String getPolicyScopeAndNameWithUniqueId() {
- return normalizePolicyScopeName(modelName + "." + getCurrentPolicyName() + "_" + policyUniqueId);
+ return normalizePolicyScopeName(
+ modelName + createScopeSeparator(modelName) + getCurrentPolicyName() + "_" + policyUniqueId);
}
/**
* @return the currentPolicyScopeAndFullPolicyName
*/
public String getCurrentPolicyScopeAndFullPolicyName(String policyNamePrefix) {
- return normalizePolicyScopeName(modelName + "." + policyNamePrefix + getCurrentPolicyName());
- }
-
- /**
- * @return the currentPolicyScopeAndFullPolicyNameWithVersion
- */
- public String getCurrentPolicyScopeAndFullPolicyNameWithVersion(String policyNamePrefix, int version) {
return normalizePolicyScopeName(
- modelName + "." + policyNamePrefix + getCurrentPolicyName() + "." + version + ".xml");
+ modelName + createScopeSeparator(modelName) + policyNamePrefix + getCurrentPolicyName());
}
/**
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java
index 17312442..32f26e99 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java
@@ -65,7 +65,7 @@ public class CsarInstallerImpl implements CsarInstaller {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(CsarInstallerImpl.class);
private Map<String, BlueprintParserFilesConfiguration> bpmnMapping = new HashMap<>();
- public static final String TEMPLATE_NAME_PREFIX = "DCAE-Designer-ClosedLoopTemplate-";
+ public static final String TEMPLATE_NAME_PREFIX = "DCAE-Designer-Template-";
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
@@ -109,8 +109,17 @@ public class CsarInstallerImpl implements CsarInstaller {
return alreadyInstalled;
}
- public static String buildModelName(CsarHandler csar, String resourceInstanceName) {
- return MODEL_NAME_PREFIX + csar.getSdcCsarHelper().getServiceMetadata().getValue("name") + "_v"
+ public static String buildModelName(CsarHandler csar, String resourceInstanceName)
+ throws SdcArtifactInstallerException {
+ String policyScopePrefix = searchForPolicyScopePrefix(csar.getMapOfBlueprints().get(resourceInstanceName));
+ if (policyScopePrefix.contains("*")) {
+ // This is policy_filter type
+ policyScopePrefix = policyScopePrefix.replaceAll("\\*", "");
+ } else {
+ // This is normally the get_input case
+ policyScopePrefix = MODEL_NAME_PREFIX;
+ }
+ return policyScopePrefix + csar.getSdcCsarHelper().getServiceMetadata().getValue("name") + "_v"
+ csar.getSdcNotification().getServiceVersion().replace('.', '_') + "_" + resourceInstanceName;
}
@@ -155,7 +164,8 @@ public class CsarInstallerImpl implements CsarInstaller {
return listConfig.get(0);
}
- private String searchForPolicyName(BlueprintArtifact blueprintArtifact) throws SdcArtifactInstallerException {
+ private static String searchForPolicyScopePrefix(BlueprintArtifact blueprintArtifact)
+ throws SdcArtifactInstallerException {
String policyName = null;
Yaml yaml = new Yaml();
List<String> policyNameList = new ArrayList<>();
@@ -186,6 +196,17 @@ public class CsarInstallerImpl implements CsarInstaller {
return policyNameList.get(0);
}
+ /**
+ * This call must be done when deploying the SDC notification as this call
+ * get the latest version of the artifact (version can be specified to DCAE
+ * call)
+ *
+ * @param blueprintArtifact
+ * @return
+ * @throws IOException
+ * @throws ParseException
+ * @throws InterruptedException
+ */
private String queryDcaeToGetServiceTypeId(BlueprintArtifact blueprintArtifact)
throws IOException, ParseException, InterruptedException {
return dcaeInventoryService.getDcaeInformation(blueprintArtifact.getBlueprintArtifactName(),
@@ -194,7 +215,7 @@ public class CsarInstallerImpl implements CsarInstaller {
}
private CldsTemplate createFakeCldsTemplate(CsarHandler csar, BlueprintArtifact blueprintArtifact,
- BlueprintParserFilesConfiguration configFiles) throws IOException {
+ BlueprintParserFilesConfiguration configFiles) throws IOException, SdcArtifactInstallerException {
CldsTemplate template = new CldsTemplate();
template.setBpmnId("Sdc-Generated");
template.setBpmnText(
@@ -221,24 +242,14 @@ public class CsarInstallerImpl implements CsarInstaller {
cldsModel.setTemplateId(cldsTemplate.getId());
cldsModel.setBpmnText(cldsTemplate.getBpmnText());
cldsModel.setTypeId(serviceTypeId);
- ModelProperties modelProp = new ModelProperties(cldsModel.getName(), "test", "PUT", false,
- cldsBpmnTransformer.doXslTransformToString(cldsTemplate.getBpmnText()), "{}");
- String policyName = searchForPolicyName(blueprintArtifact);
- String inputParams = "";
- if (policyName.contains("*")) {
- // It's a filter must add a specific prefix
- cldsModel.setControlNamePrefix(policyName);
- } else {
- cldsModel.setControlNamePrefix(CONTROL_NAME_PREFIX);
- inputParams = "{\"name\":\"deployParameters\",\"value\":{\n" + "\"policy_id\": \""
- + modelProp.getPolicyNameForDcaeDeploy(refProp) + "\"" + "}}";
- }
- cldsModel.setPropText("{\"global\":[{\"name\":\"service\",\"value\":[\""
- + blueprintArtifact.getBlueprintInvariantServiceUuid() + "\"]},{\"name\":\"vf\",\"value\":[\""
- + blueprintArtifact.getResourceAttached().getResourceInvariantUUID()
- + "\"]},{\"name\":\"actionSet\",\"value\":[\"vnfRecipe\"]},{\"name\":\"location\",\"value\":[\"DC1\"]},"
- + inputParams + "]}");
+ cldsModel.setControlNamePrefix(CONTROL_NAME_PREFIX);
+ // We must save it otherwise object won't be created in db
+ // and proptext will always be null
+ cldsModel.setPropText("{\"global\":[]}");
+ // Must save first to have the generated id available to generate
+ // the policyId
cldsModel = cldsModel.save(cldsDao, null);
+ cldsModel = setModelPropText(cldsModel, blueprintArtifact, cldsTemplate);
logger.info("Fake Clds Model created for blueprint " + blueprintArtifact.getBlueprintArtifactName()
+ " with name " + cldsModel.getName());
return cldsModel;
@@ -246,4 +257,18 @@ public class CsarInstallerImpl implements CsarInstaller {
throw new SdcArtifactInstallerException("TransformerException when decoding the BpmnText", e);
}
}
+
+ private CldsModel setModelPropText(CldsModel cldsModel, BlueprintArtifact blueprintArtifact,
+ CldsTemplate cldsTemplate) throws TransformerException {
+ ModelProperties modelProp = new ModelProperties(cldsModel.getName(), cldsModel.getControlName(), "PUT", false,
+ cldsBpmnTransformer.doXslTransformToString(cldsTemplate.getBpmnText()), "{}");
+ String inputParams = "{\"name\":\"deployParameters\",\"value\":{\n" + "\"policy_id\": \""
+ + "AUTO_GENERATED_POLICY_ID_AT_SUBMIT" + "\"" + "}}";
+ cldsModel.setPropText("{\"global\":[{\"name\":\"service\",\"value\":[\""
+ + blueprintArtifact.getBlueprintInvariantServiceUuid() + "\"]},{\"name\":\"vf\",\"value\":[\""
+ + blueprintArtifact.getResourceAttached().getResourceInvariantUUID()
+ + "\"]},{\"name\":\"actionSet\",\"value\":[\"vnfRecipe\"]},{\"name\":\"location\",\"value\":[\"DC1\"]},"
+ + inputParams + "]}");
+ return cldsModel.save(cldsDao, null);
+ }
}