Search in sources :

Example 1 with AbstractInheritableToscaType

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));
}
Also used : AbstractInheritableToscaType(org.alien4cloud.tosca.model.types.AbstractInheritableToscaType) Test(org.junit.Test)

Example 2 with AbstractInheritableToscaType

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;
}
Also used : AbstractInheritableToscaType(org.alien4cloud.tosca.model.types.AbstractInheritableToscaType)

Example 3 with AbstractInheritableToscaType

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();
}
Also used : PendingException(cucumber.api.PendingException) AbstractInheritableToscaType(org.alien4cloud.tosca.model.types.AbstractInheritableToscaType) Given(cucumber.api.java.en.Given)

Example 4 with AbstractInheritableToscaType

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);
}
Also used : AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) NotFoundException(alien4cloud.exception.NotFoundException) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) AbstractInheritableToscaType(org.alien4cloud.tosca.model.types.AbstractInheritableToscaType) Location(alien4cloud.model.orchestrators.locations.Location)

Example 5 with AbstractInheritableToscaType

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");
                }
            }
        }
    }
}
Also used : InvalidArgumentException(alien4cloud.exception.InvalidArgumentException) NotFoundException(alien4cloud.exception.NotFoundException) AbstractInheritableToscaType(org.alien4cloud.tosca.model.types.AbstractInheritableToscaType) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) ValidValuesConstraint(org.alien4cloud.tosca.model.definitions.constraints.ValidValuesConstraint) EqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint) PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint)

Aggregations

AbstractInheritableToscaType (org.alien4cloud.tosca.model.types.AbstractInheritableToscaType)10 NotFoundException (alien4cloud.exception.NotFoundException)2 IndexingServiceException (alien4cloud.exception.IndexingServiceException)1 InvalidArgumentException (alien4cloud.exception.InvalidArgumentException)1 AbstractLocationResourceTemplate (alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate)1 Location (alien4cloud.model.orchestrators.locations.Location)1 AbstractRelationshipTask (alien4cloud.topology.task.AbstractRelationshipTask)1 ToscaContextual (alien4cloud.tosca.context.ToscaContextual)1 ParsingError (alien4cloud.tosca.parser.ParsingError)1 PendingException (cucumber.api.PendingException)1 Given (cucumber.api.java.en.Given)1 ArrayList (java.util.ArrayList)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 PropertyConstraint (org.alien4cloud.tosca.model.definitions.PropertyConstraint)1 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)1 EqualConstraint (org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint)1 ValidValuesConstraint (org.alien4cloud.tosca.model.definitions.constraints.ValidValuesConstraint)1 AbstractToscaType (org.alien4cloud.tosca.model.types.AbstractToscaType)1 ArtifactType (org.alien4cloud.tosca.model.types.ArtifactType)1