public class BlueprintParserMappingConfiguration {
private String blueprintKey;
+ private boolean dcaeDeployable;
private BlueprintParserFilesConfiguration files;
public String getBlueprintKey() {
this.files = filesConfig;
}
+ public boolean isDcaeDeployable() {
+ return dcaeDeployable;
+ }
+
public static List<BlueprintParserMappingConfiguration> createFromJson(InputStream json) throws IOException {
TypeReference<List<BlueprintParserMappingConfiguration>> mapType = new TypeReference<List<BlueprintParserMappingConfiguration>>() {
};
*/
public class CldsModel {
- private static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsModel.class);
- private static final int UUID_LENGTH = 36;
- private static final String STATUS_DESIGN = "DESIGN";
- private static final String STATUS_DISTRIBUTED = "DISTRIBUTED";
- private static final String STATUS_ACTIVE = "ACTIVE";
- private static final String STATUS_STOPPED = "STOPPED";
- private static final String STATUS_DELETING = "DELETING";
- private static final String STATUS_ERROR = "ERROR";
- private static final String STATUS_UNKNOWN = "UNKNOWN";
- private String id;
- private String templateId;
- private String templateName;
- private String name;
- private String controlNamePrefix;
- private String controlNameUuid;
- private String bpmnText;
- private String propText;
- private String imageText;
- private String docText;
- private String blueprintText;
- private CldsEvent event;
- private String status;
- private List<String> permittedActionCd;
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsModel.class);
+ private static final int UUID_LENGTH = 36;
+ private static final String STATUS_DESIGN = "DESIGN";
+ private static final String STATUS_DISTRIBUTED = "DISTRIBUTED";
+ private static final String STATUS_ACTIVE = "ACTIVE";
+ private static final String STATUS_STOPPED = "STOPPED";
+ private static final String STATUS_DELETING = "DELETING";
+ private static final String STATUS_ERROR = "ERROR";
+ private static final String STATUS_UNKNOWN = "UNKNOWN";
+ private String id;
+ private String templateId;
+ private String templateName;
+ private String name;
+ private String controlNamePrefix;
+ private String controlNameUuid;
+ private String bpmnText;
+ private String propText;
+ private String imageText;
+ private String docText;
+ private String blueprintText;
+ private CldsEvent event;
+ private String status;
+ private List<String> permittedActionCd;
private List<CldsModelInstance> cldsModelInstanceList;
- private String typeId;
- private String typeName;
- private String deploymentId;
+ /**
+ * The service type Id received from DCAE by querying it
+ */
+ private String typeId;
+ private String typeName;
+ private String deploymentId;
/**
* Construct empty model.
public boolean canInventoryCall() {
boolean canCall = false;
/* Below checks the clds event is submit/resubmit */
-
if ((event.isActionCd(CldsEvent.ACTION_SUBMIT) || event.isActionCd(CldsEvent.ACTION_RESUBMIT)
|| event.isActionCd(CldsEvent.ACTION_SUBMITDCAE))) {
canCall = true;
* set the status in the model
*/
private void determineStatus() {
-
status = STATUS_UNKNOWN;
if (event == null || event.getActionCd() == null) {
status = STATUS_DESIGN;
} else if (event.isActionAndStateCd(CldsEvent.ACTION_STOP, CldsEvent.ACTION_STATE_ANY)) {
status = STATUS_STOPPED;
}
-
}
/**
public List<String> getPermittedActionCd() {
return permittedActionCd;
}
-
}
import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException;
import org.openecomp.sdc.api.notification.IArtifactInfo;
import org.openecomp.sdc.api.notification.INotificationData;
+import org.openecomp.sdc.api.notification.IResourceInstance;
import org.openecomp.sdc.api.results.IDistributionClientDownloadResult;
import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
private SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
private ISdcCsarHelper sdcCsarHelper;
private String dcaeBlueprint;
+ private String blueprintArtifactName;
+ private String blueprintInvariantResourceUuid;
+ private String blueprintInvariantServiceUuid;
public static final String CSAR_TYPE = "TOSCA_CSAR";
+ private INotificationData sdcNotification;
public CsarHandler(INotificationData iNotif, String controller, String clampCsarPath) throws CsarHandlerException {
+ this.sdcNotification = iNotif;
this.controllerName = controller;
this.artifactElement = searchForUniqueCsar(iNotif);
this.csarFilePath = buildFilePathForCsar(artifactElement, clampCsarPath);
}
sdcCsarHelper = factory.getSdcCsarHelper(csarFilePath);
this.loadDcaeBlueprint();
+ this.loadBlueprintArtifactDetails();
} catch (IOException e) {
throw new SdcArtifactInstallerException(
"Exception caught when trying to write the CSAR on the file system to " + csarFilePath, e);
}
}
+ private void loadBlueprintArtifactDetails() {
+ blueprintInvariantServiceUuid = this.getSdcNotification().getServiceInvariantUUID();
+ for (IResourceInstance resource : this.getSdcNotification().getResources()) {
+ if ("VF".equals(resource.getResourceType())) {
+ for (IArtifactInfo artifact : resource.getArtifacts()) {
+ if ("DCAE_INVENTORY_BLUEPRINT".equals(artifact.getArtifactType())) {
+ blueprintArtifactName = artifact.getArtifactName();
+ blueprintInvariantResourceUuid = resource.getResourceInvariantUUID();
+ }
+ }
+ }
+ }
+ }
+
private void loadDcaeBlueprint() throws IOException, SdcArtifactInstallerException {
List<ZipEntry> listEntries = new ArrayList<>();
try (ZipFile zipFile = new ZipFile(csarFilePath)) {
public synchronized String getDcaeBlueprint() {
return dcaeBlueprint;
}
+
+ public INotificationData getSdcNotification() {
+ return sdcNotification;
+ }
+
+ public String getBlueprintArtifactName() {
+ return blueprintArtifactName;
+ }
+
+ public String getBlueprintInvariantResourceUuid() {
+ return blueprintInvariantResourceUuid;
+ }
+
+ public String getBlueprintInvariantServiceUuid() {
+ return blueprintInvariantServiceUuid;
+ }
}
import javax.annotation.PostConstruct;
-import org.onap.clamp.clds.config.ClampProperties;
+import org.json.simple.parser.ParseException;
+import org.onap.clamp.clds.client.DcaeInventoryServices;
import org.onap.clamp.clds.config.sdc.BlueprintParserFilesConfiguration;
import org.onap.clamp.clds.config.sdc.BlueprintParserMappingConfiguration;
import org.onap.clamp.clds.dao.CldsDao;
private static final EELFLogger logger = EELFManager.getInstance().getLogger(CsarInstallerImpl.class);
private Map<String, BlueprintParserFilesConfiguration> bpmnMapping = new HashMap<>();
- public static final String TEMPLATE_NAME_SUFFIX = "-template-dcae-designer";
- public static final String MODEL_NAME_SUFFIX = "-model-dcae-designer";
+ public static final String TEMPLATE_NAME_PREFIX = "DCAE-Designer-ClosedLoopTemplate-";
+ public static final String MODEL_NAME_PREFIX = "DCAE-Designer-ClosedLoopInstance-";
/**
* The file name that will be loaded by Spring.
*/
@Autowired
private CldsDao cldsDao;
@Autowired
- private ClampProperties refProp;
- @Autowired
CldsTemplateService cldsTemplateService;
@Autowired
CldsService cldsService;
+ @Autowired
+ DcaeInventoryServices dcaeInventoryService;
@PostConstruct
public void loadConfiguration() throws IOException {
@Override
public void installTheCsar(CsarHandler csar) throws SdcArtifactInstallerException {
try {
- BlueprintParserFilesConfiguration configFiles = this.searchForRightMapping(csar);
- createFakeCldsModel(csar, configFiles, createFakeCldsTemplate(csar, configFiles));
+ String serviceTypeId = queryDcaeToGetServiceTypeId(csar);
+ String policyName = searchForPolicyName(csar);
+ if (policyName.contains("*")) {
+ }
+ createFakeCldsModel(csar, createFakeCldsTemplate(csar, this.searchForRightMapping(csar)), serviceTypeId);
} catch (IOException e) {
throw new SdcArtifactInstallerException("Exception caught during the Csar installation in database", e);
+ } catch (ParseException e) {
+ throw new SdcArtifactInstallerException("Exception caught during the Dcae query to get ServiceTypeId", e);
}
}
return listConfig.get(0);
}
- private String createTemplateName(CsarHandler csar) {
- return csar.getSdcCsarHelper().getServiceMetadata().getValue("name") + TEMPLATE_NAME_SUFFIX;
+ private String searchForPolicyName(CsarHandler csar) throws SdcArtifactInstallerException {
+ String policyName = null;
+ Yaml yaml = new Yaml();
+ List<String> policyNameList = new ArrayList<>();
+ Map<String, Object> templateNodes = ((Map<String, Object>) ((Map<String, Object>) yaml
+ .load(csar.getDcaeBlueprint())).get("node_templates"));
+ templateNodes.entrySet().stream().filter(e -> e.getKey().contains("policy_")).forEach(ef -> {
+ String filteredPolicyName = (String) ((Map<String, Object>) ((Map<String, Object>) ef.getValue())
+ .get("properties")).get("policy_filter");
+ if (policyName != null) {
+ policyNameList.add(filteredPolicyName);
+ } else {
+ String inputPolicyName = (String) ((Map<String, Object>) ((Map<String, Object>) ((Map<String, Object>) ef
+ .getValue()).get("properties")).get("policy_id")).get("get_input");
+ if (inputPolicyName != null) {
+ policyNameList.add("get_input");
+ }
+ }
+ });
+ if (policyNameList.size() > 1) {
+ throw new SdcArtifactInstallerException(
+ "The code does not currently support multiple Policy MicroServices in the blueprint");
+ } else if (policyNameList.isEmpty()) {
+ throw new SdcArtifactInstallerException(
+ "There is no recognized Policy MicroService found in the blueprint");
+ }
+ return policyNameList.get(0);
}
- private String createModelName(CsarHandler csar) {
- return csar.getSdcCsarHelper().getServiceMetadata().getValue("name") + MODEL_NAME_SUFFIX;
+ private String queryDcaeToGetServiceTypeId(CsarHandler csar) throws IOException, ParseException {
+ return dcaeInventoryService.getDcaeInformation(csar.getBlueprintArtifactName(),
+ csar.getBlueprintInvariantServiceUuid(), csar.getBlueprintInvariantResourceUuid());
}
private CldsTemplate createFakeCldsTemplate(CsarHandler csar, BlueprintParserFilesConfiguration configFiles)
template.setBpmnId("Sdc-Generated");
template.setBpmnText(
IOUtils.toString(appContext.getResource(configFiles.getBpmnXmlFilePath()).getInputStream()));
- // ((ObjectNode)refProp.getJsonTemplate(CldsService.GLOBAL_PROPERTIES_KEY));
template.setPropText(csar.getDcaeBlueprint());
template.setImageText(
IOUtils.toString(appContext.getResource(configFiles.getSvgXmlFilePath()).getInputStream()));
- return cldsTemplateService.putTemplate(createTemplateName(csar), template);
+ template.setName(TEMPLATE_NAME_PREFIX + csar.getSdcCsarHelper().getServiceMetadata().getValue("name"));
+ template.save(cldsDao, null);
+ return template;
}
- private CldsModel createFakeCldsModel(CsarHandler csar, BlueprintParserFilesConfiguration configFiles,
- CldsTemplate cldsTemplate) {
+ private CldsModel createFakeCldsModel(CsarHandler csar, CldsTemplate cldsTemplate, String serviceTypeId) {
CldsModel cldsModel = new CldsModel();
+ cldsModel.setControlNamePrefix(MODEL_NAME_PREFIX);
+ cldsModel.setName(csar.getSdcCsarHelper().getServiceMetadata().getValue("name"));
cldsModel.setBlueprintText(csar.getDcaeBlueprint());
cldsModel.setTemplateName(cldsTemplate.getName());
- // cldsModel.set
- return cldsService.putModel(createModelName(csar), cldsModel);
+ cldsModel.setTemplateId(cldsTemplate.getId());
+ cldsModel.setDocText(cldsTemplate.getPropText());
+ cldsModel.setPropText("{}");
+ cldsModel.setBpmnText(cldsTemplate.getBpmnText());
+ cldsModel.setTypeId(serviceTypeId);
+ cldsModel.save(cldsDao, null);
+ return cldsModel;
}
}
<choice>
<when>
<simple> ${exchangeProperty.actionCd} == 'SUBMIT' || ${exchangeProperty.actionCd} == 'RESUBMIT'</simple>
- <to uri="bean:org.onap.clamp.clds.client.SdcSendReqDelegate" />
<to uri="bean:org.onap.clamp.clds.client.TcaPolicyDelegate" />
<to uri="bean:org.onap.clamp.clds.client.HolmesPolicyDelegate" />
<to uri="bean:org.onap.clamp.clds.client.OperationalPolicyDelegate" />
import org.onap.clamp.clds.dao.CldsDao;
import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException;
import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException;
+import org.onap.clamp.clds.model.CldsModel;
import org.onap.clamp.clds.model.CldsTemplate;
import org.onap.clamp.clds.sdc.controller.installer.CsarHandler;
import org.onap.clamp.clds.sdc.controller.installer.CsarInstaller;
Mockito.when(csarHelper.getServiceMetadata()).thenReturn(data);
Mockito.when(csarHandler.getSdcCsarHelper()).thenReturn(csarHelper);
csarInstaller.installTheCsar(csarHandler);
- // Get it back from DB
+ // Get the template back from DB
CldsTemplate templateFromDB = CldsTemplate.retrieve(cldsDao,
generatedName + CsarInstallerImpl.TEMPLATE_NAME_SUFFIX, false);
assertNotNull(templateFromDB);
assertNotNull(templateFromDB.getImageText());
assertNotNull(templateFromDB.getPropText());
assertEquals(templateFromDB.getName(), generatedName + CsarInstallerImpl.TEMPLATE_NAME_SUFFIX);
+ // Get the Model back from DB
+ CldsModel modelFromDB = CldsModel.retrieve(cldsDao, generatedName + CsarInstallerImpl.MODEL_NAME_SUFFIX, false);
+ assertNotNull(modelFromDB);
+ assertNotNull(modelFromDB.getBpmnText());
+ assertNotNull(modelFromDB.getImageText());
+ assertNotNull(modelFromDB.getPropText());
+ assertEquals(modelFromDB.getName(), generatedName + CsarInstallerImpl.MODEL_NAME_SUFFIX);
}
}
[
{
"blueprintKey": "tca_",
+ "dcaeDeployable":"true",
"files": {
"bpmnXmlFilePath": "classpath:/clds/templates/bpmn/tca-template.xml",
"svgXmlFilePath": "classpath:/clds/templates/bpmn/tca-img.xml"
},
{
"blueprintKey": "holmes_",
+ "dcaeDeployable":"false",
"files": {
"bpmnXmlFilePath": "classpath:/clds/templates/bpmn/holmes-template.xml",
"svgXmlFilePath": "classpath:/clds/templates/bpmn/holmes-img.xml"
topic1_client_role:
type: string
node_templates:
+ policy_0:
+ type: dcae.nodes.policy
+ properties:
+ policy_model: policy.nodes.holmes
+ policy_filter: "DCAE.Config_Holmes.*"
docker_host_host:
type: dcae.nodes.SelectedDockerHost
properties:
type: dcae.relationships.subscribe_to_events
- target: topic1
type: dcae.relationships.subscribe_to_events
+ - target: policy_0
+ type: dcae.relationships.depends_on
topic0:
type: dcae.nodes.Topic
properties:
type: string
service_id:
type: string
+ policy_id:
+ type: string
node_templates:
+ policy_0:
+ type: dcae.nodes.policy
+ properties:
+ policy_id:
+ get_input: policy_id
cdap_host_host:
type: dcae.nodes.StreamingAnalytics.SelectedCDAPInfrastructure
properties:
get_input: service_id
streamname: TCASubscriberOutputStream
relationships:
+ - target: topic0
+ type: dcae.relationships.subscribe_to_events
+ - target: topic1
+ type: dcae.relationships.publish_events
- target: cdap_host_host
- type: dcae.relationships.component_contained_in
\ No newline at end of file
+ type: dcae.relationships.component_contained_in
+ - target: policy_0
+ type: dcae.relationships.depends_on
+ topic0:
+ type: dcae.nodes.Topic
+ properties:
+ topic_name: ''
+ topic1:
+ type: dcae.nodes.Topic
+ properties:
+ topic_name: ''
+
\ No newline at end of file