use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.
the class SearchDefinitionSteps method createAndIndexComponent.
private void createAndIndexComponent(int count, String type, String baseName, int countHavingProperty, String property, String propertyValue) throws Exception {
testDataList.clear();
Class<?> clazz = QUERY_TYPES.get(type).getIndexedToscaElementClass();
String typeName = MappingBuilder.indexTypeFromClass(clazz);
int remaining = countHavingProperty;
baseName = baseName == null || baseName.isEmpty() ? typeName : baseName;
for (int i = 0; i < count; i++) {
AbstractToscaType componentTemplate = (AbstractToscaType) clazz.newInstance();
String elementId = baseName + "_" + i;
componentTemplate.setElementId(elementId);
componentTemplate.setArchiveVersion(DEFAULT_ARCHIVE_VERSION);
componentTemplate.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
if (property != null && remaining > 0) {
if (type.equalsIgnoreCase("node types")) {
switch(property) {
case "capability":
((NodeType) componentTemplate).setCapabilities(Lists.newArrayList(new CapabilityDefinition(propertyValue, propertyValue, 1)));
break;
case "requirement":
((NodeType) componentTemplate).setRequirements((Lists.newArrayList(new RequirementDefinition(propertyValue, propertyValue))));
break;
case "default capability":
((NodeType) componentTemplate).setDefaultCapabilities((Lists.newArrayList(propertyValue)));
break;
case "elementId":
((NodeType) componentTemplate).setElementId(propertyValue);
break;
default:
break;
}
} else if (type.equalsIgnoreCase("relationship types")) {
((RelationshipType) componentTemplate).setValidSources(new String[] { propertyValue });
}
remaining -= 1;
}
String serializeDatum = JsonUtil.toString(componentTemplate);
log.debug("Saving in ES: " + serializeDatum);
esClient.prepareIndex(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName).setSource(serializeDatum).setRefresh(true).execute().actionGet();
if (componentTemplate instanceof NodeType) {
testDataList.add((NodeType) (componentTemplate));
}
}
indexedComponentTypes.put(type, typeName);
}
use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.
the class NodeMatcherService method populateLocationResourcesWithServiceResource.
/**
* Populate this {@link LocationResources} using these {@link ServiceResource}s in order to make them available as {@link LocationResourceTemplate} for
* matching purpose.
*
* TODO: Improve this ugly code to put ServiceResource in LocationResourceTemplates.
*/
private void populateLocationResourcesWithServiceResource(LocationResources locationResources, List<ServiceResource> services, String locationId) {
for (ServiceResource serviceResource : services) {
LocationResourceTemplate lrt = new LocationResourceTemplate();
lrt.setService(true);
lrt.setEnabled(true);
// for a service we also want to display the version, so just add it to the name
lrt.setName(serviceResource.getName() + ":" + serviceResource.getVersion());
lrt.setId(serviceResource.getId());
ServiceNodeTemplate serviceNodeTemplate = new ServiceNodeTemplate(serviceResource.getNodeInstance());
lrt.setTemplate(serviceNodeTemplate);
lrt.setLocationId(locationId);
String serviceTypeName = serviceResource.getNodeInstance().getNodeTemplate().getType();
List<String> types = Lists.newArrayList(serviceTypeName);
lrt.setTypes(types);
NodeType serviceType = toscaTypeSearchService.findOrFail(NodeType.class, serviceTypeName, serviceResource.getNodeInstance().getTypeVersion());
types.addAll(serviceType.getDerivedFrom());
locationResources.getNodeTypes().put(serviceTypeName, serviceType);
Csar csar = toscaTypeSearchService.getArchive(serviceType.getArchiveName(), serviceType.getArchiveVersion());
Set<CSARDependency> dependencies = Sets.newHashSet();
if (csar.getDependencies() != null) {
dependencies.addAll(csar.getDependencies());
}
dependencies.add(new CSARDependency(csar.getName(), csar.getVersion()));
if (serviceType.getCapabilities() != null && !serviceType.getCapabilities().isEmpty()) {
for (CapabilityDefinition capabilityDefinition : serviceType.getCapabilities()) {
locationResources.getCapabilityTypes().put(capabilityDefinition.getType(), csarRepoSearchService.getRequiredElementInDependencies(CapabilityType.class, capabilityDefinition.getType(), dependencies));
}
}
locationResources.getNodeTemplates().add(lrt);
}
}
use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.
the class TopologyCapabilityBoundsValidationServices method isCapabilityUpperBoundReachedForTarget.
//
public boolean isCapabilityUpperBoundReachedForTarget(String nodeTemplateName, Map<String, NodeTemplate> nodeTemplates, String capabilityName, Set<CSARDependency> dependencies) {
NodeTemplate nodeTemplate = nodeTemplates.get(nodeTemplateName);
NodeType relatedIndexedNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), dependencies);
chekCapability(nodeTemplateName, capabilityName, nodeTemplate);
CapabilityDefinition capabilityDefinition = getCapabilityDefinition(relatedIndexedNodeType.getCapabilities(), capabilityName);
if (capabilityDefinition.getUpperBound() == Integer.MAX_VALUE) {
return false;
}
List<RelationshipEntry> targetRelatedRelationships = TopologyUtils.getTargetRelationships(nodeTemplateName, nodeTemplates);
if (targetRelatedRelationships == null || targetRelatedRelationships.isEmpty()) {
return false;
}
int count = 0;
for (RelationshipEntry relationshipEntry : targetRelatedRelationships) {
if (relationshipEntry.getRelationship().getTargetedCapabilityName().equals(capabilityName)) {
count++;
}
}
return count >= capabilityDefinition.getUpperBound();
}
use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.
the class ServiceResourceService method validateRelationshipTypes.
private void validateRelationshipTypes(ServiceResource serviceResource, final NodeType nodeType) {
safe(serviceResource.getCapabilitiesRelationshipTypes()).forEach((capabilityName, relationshipTypeId) -> {
RelationshipType relationshipType = toscaTypeSearchService.findByIdOrFail(RelationshipType.class, relationshipTypeId);
String[] validTargets = relationshipType.getValidTargets();
if (ArrayUtils.isNotEmpty(validTargets)) {
CapabilityDefinition capabilityDefinition = nodeType.getCapabilities().stream().filter(c -> c.getId().equals(capabilityName)).findFirst().get();
Csar csar = toscaTypeSearchService.getArchive(nodeType.getArchiveName(), nodeType.getArchiveVersion());
Set<CSARDependency> allDependencies = new HashSet<>(safe(csar.getDependencies()));
allDependencies.add(new CSARDependency(csar.getName(), csar.getVersion(), csar.getHash()));
CapabilityType capabilityType = toscaTypeSearchService.getElementInDependencies(CapabilityType.class, capabilityDefinition.getType(), allDependencies);
Set<String> allAcceptedTypes = new HashSet<>();
allAcceptedTypes.addAll(capabilityType.getDerivedFrom());
allAcceptedTypes.add(capabilityType.getElementId());
boolean isValid = false;
for (String validTarget : validTargets) {
if (allAcceptedTypes.contains(validTarget)) {
isValid = true;
break;
}
}
if (!isValid) {
throw new IncompatibleHalfRelationshipException("[" + relationshipType.getId() + "] is not compatible with [" + capabilityType.getId() + "]");
}
}
});
safe(serviceResource.getRequirementsRelationshipTypes()).forEach((k, v) -> {
toscaTypeSearchService.findByIdOrFail(RelationshipType.class, v);
});
}
use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.
the class EsDaoCrudTest method prepareToscaElement.
private void prepareToscaElement() {
List<CapabilityDefinition> capa = Arrays.asList(new CapabilityDefinition("container", "container", 1), new CapabilityDefinition("container1", "container1", 1), new CapabilityDefinition("container2", "container2", 1), new CapabilityDefinition("container3", "container3", 1));
List<RequirementDefinition> req = Arrays.asList(new RequirementDefinition("Runtime", "Runtime"), new RequirementDefinition("server", "server"), new RequirementDefinition("blob", "blob"));
List<String> der = Arrays.asList("Parent1", "Parent2");
indexedNodeTypeTest = TestModelUtil.createIndexedNodeType("1", "positive", "1.0", "", capa, req, der, new ArrayList<String>(0), threeTags, new Date(), new Date());
}
Aggregations