use of org.alien4cloud.tosca.model.types.AbstractInheritableToscaType in project alien4cloud by alien4cloud.
the class IndexedModelTest method testOrderInheritableElements.
@Test
public void testOrderInheritableElements() {
List<AbstractInheritableToscaType> sorted = IndexedModelUtils.orderByDerivedFromHierarchy(elementsByIdMap);
for (AbstractInheritableToscaType el : sorted) {
System.out.println(el.getElementId() + " " + el.getDerivedFrom());
}
assertTrue(sorted.indexOf(root) < sorted.indexOf(child1));
assertTrue(sorted.indexOf(root) < sorted.indexOf(child2));
assertTrue(sorted.indexOf(child1) < sorted.indexOf(grandChild1));
assertTrue(sorted.indexOf(child1) < sorted.indexOf(grandChild2));
}
use of org.alien4cloud.tosca.model.types.AbstractInheritableToscaType in project alien4cloud by alien4cloud.
the class IndexedModelTest method fabricElement.
private static AbstractInheritableToscaType fabricElement(Map<String, AbstractInheritableToscaType> map, String elementId, String derivedFrom, List<Tag> tags) {
AbstractInheritableToscaType element = new AbstractInheritableToscaType();
element.setElementId(elementId);
element.setArchiveVersion("1.0");
element.setDerivedFrom(Arrays.asList(derivedFrom));
map.put(element.getElementId(), element);
return element;
}
use of org.alien4cloud.tosca.model.types.AbstractInheritableToscaType in project alien4cloud by alien4cloud.
the class TopologyStepDefinitions method I_create_a_in_an_archive_name_version.
@Given("^I create a \"([^\"]*)\" \"([^\"]*)\" in an archive name \"([^\"]*)\" version \"([^\"]*)\"$")
public void I_create_a_in_an_archive_name_version(String componentType, String elementId, String archiveName, String archiveVersion) throws Throwable {
AbstractInheritableToscaType element = new AbstractInheritableToscaType();
element.setAbstract(false);
element.setElementId(elementId);
element.setArchiveName(archiveName);
element.setArchiveVersion(archiveVersion);
element.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
Class<?> clazz = null;
if (componentType.equals("capability") || componentType.equals("capabilities")) {
clazz = CapabilityType.class;
} else {
throw new PendingException("creation of Type " + componentType + "not supported!");
}
esClient.prepareIndex(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, MappingBuilder.indexTypeFromClass(clazz)).setSource(JsonUtil.toString(element)).setRefresh(true).execute().actionGet();
}
use of org.alien4cloud.tosca.model.types.AbstractInheritableToscaType in project alien4cloud by alien4cloud.
the class LocationResourceService method setTemplateProperty.
/*
* (non-Javadoc)
*
* @see alien4cloud.orchestrators.locations.services.ILocationResourceService#setTemplateProperty(java.lang.String, java.lang.String,
* java.lang.Object)
*/
@Override
public void setTemplateProperty(String resourceId, String propertyName, Object propertyValue) throws ConstraintValueDoNotMatchPropertyTypeException, ConstraintViolationException {
AbstractLocationResourceTemplate resourceTemplate = getOrFail(resourceId);
Location location = locationService.getOrFail(resourceTemplate.getLocationId());
AbstractInheritableToscaType resourceType = (AbstractInheritableToscaType) csarRepoSearchService.getRequiredElementInDependencies(AbstractToscaType.class, resourceTemplate.getTemplate().getType(), location.getDependencies());
if (!safe(resourceType.getProperties()).containsKey(propertyName)) {
throw new NotFoundException("Property [" + propertyName + "] is not found in type [" + resourceType.getElementId() + "]");
}
propertyService.setPropertyValue(location.getDependencies(), resourceTemplate.getTemplate(), resourceType.getProperties().get(propertyName), propertyName, propertyValue);
saveResource(resourceTemplate);
}
use of org.alien4cloud.tosca.model.types.AbstractInheritableToscaType in project alien4cloud by alien4cloud.
the class SuggestionService method setSuggestionIdOnPropertyDefinition.
/**
* Add the suggestion ID of the new suggestionEntry to the appropriate propertyDefinition.
*
* @param suggestionEntry entry of suggestion
*/
public void setSuggestionIdOnPropertyDefinition(SuggestionEntry suggestionEntry) {
Class<? extends AbstractInheritableToscaType> targetClass = (Class<? extends AbstractInheritableToscaType>) alienDAO.getTypesToClasses().get(suggestionEntry.getEsType());
// FIXME what if targetClass is null ?
Object array = toscaTypeSearchService.findAll(targetClass, suggestionEntry.getTargetElementId());
if (array != null) {
int length = Array.getLength(array);
for (int i = 0; i < length; i++) {
AbstractInheritableToscaType targetElement = ((AbstractInheritableToscaType) Array.get(array, i));
PropertyDefinition propertyDefinition = targetElement.getProperties().get(suggestionEntry.getTargetProperty());
if (propertyDefinition == null) {
throw new NotFoundException("Property [" + suggestionEntry.getTargetProperty() + "] not found for element [" + suggestionEntry.getTargetElementId() + "]");
} else {
switch(propertyDefinition.getType()) {
case ToscaTypes.VERSION:
case ToscaTypes.STRING:
propertyDefinition.setSuggestionId(suggestionEntry.getId());
alienDAO.save(targetElement);
break;
case ToscaTypes.LIST:
case ToscaTypes.MAP:
PropertyDefinition entrySchema = propertyDefinition.getEntrySchema();
if (entrySchema != null) {
entrySchema.setSuggestionId(suggestionEntry.getId());
alienDAO.save(targetElement);
} else {
throw new InvalidArgumentException("Cannot suggest a list / map type with no entry schema definition");
}
break;
default:
throw new InvalidArgumentException(propertyDefinition.getType() + " cannot be suggested, only property of type string list or map can be suggested");
}
}
}
}
}
Aggregations