Search in sources :

Example 1 with ToscaTypeLoader

use of alien4cloud.tosca.container.ToscaTypeLoader in project alien4cloud by alien4cloud.

the class ToscaTypeLoaderTest method before.

@Before
public void before() {
    dependencyLoader = Mockito.mock(ICsarDependencyLoader.class);
    Mockito.when(dependencyLoader.getDependencies("tosca-base-types", "1.0")).thenReturn(new HashSet<CSARDependency>());
    Mockito.when(dependencyLoader.getDependencies("java-types", "1.0")).thenReturn(Sets.newHashSet(baseTypes));
    Mockito.when(dependencyLoader.getDependencies("java-types", "2.0")).thenReturn(Sets.newHashSet(baseTypesV2));
    loader = new ToscaTypeLoader(dependencyLoader);
}
Also used : ToscaTypeLoader(alien4cloud.tosca.container.ToscaTypeLoader) ICsarDependencyLoader(org.alien4cloud.tosca.catalog.index.ICsarDependencyLoader) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Before(org.junit.Before)

Example 2 with ToscaTypeLoader

use of alien4cloud.tosca.container.ToscaTypeLoader in project alien4cloud by alien4cloud.

the class TopologyService method unloadType.

public void unloadType(Topology topology, String... types) {
    // make sure to set the failOnTypeNotFound to false, to deal with topology recovering when a type is deleted from a dependency
    ToscaTypeLoader typeLoader = initializeTypeLoader(topology, false);
    for (String type : types) {
        typeLoader.unloadType(type);
    }
    ToscaContext.get().resetDependencies(typeLoader.getLoadedDependencies());
    // TODO update csar dependencies also ?
    topology.setDependencies(typeLoader.getLoadedDependencies());
}
Also used : ToscaTypeLoader(alien4cloud.tosca.container.ToscaTypeLoader)

Example 3 with ToscaTypeLoader

use of alien4cloud.tosca.container.ToscaTypeLoader in project alien4cloud by alien4cloud.

the class TopologyService method rebuildDependencies.

public void rebuildDependencies(Topology topology) {
    ToscaTypeLoader typeLoader = initializeTypeLoader(topology, true);
    topology.setDependencies(typeLoader.getLoadedDependencies());
}
Also used : ToscaTypeLoader(alien4cloud.tosca.container.ToscaTypeLoader)

Example 4 with ToscaTypeLoader

use of alien4cloud.tosca.container.ToscaTypeLoader in project alien4cloud by alien4cloud.

the class TopologyService method loadType.

/**
 * Load a type into the topology (add dependency for this new type, upgrade if necessary ...)
 *
 * If the dependency added has been upgraded into the topology, then recover the topology
 *
 * @param topology the topology
 * @param element the element to load
 * @param <T> tosca element type
 * @return The real loaded element if element given in argument is from older archive than topology's dependencies
 */
@SuppressWarnings("unchecked")
public <T extends AbstractToscaType> T loadType(Topology topology, T element) {
    String type = element.getElementId();
    String archiveName = element.getArchiveName();
    String archiveVersion = element.getArchiveVersion();
    CSARDependency toLoadDependency = csarDependencyLoader.buildDependencyBean(archiveName, archiveVersion);
    // FIXME Transitive dependencies could change here and thus types be affected ?
    ToscaTypeLoader typeLoader = initializeTypeLoader(topology, true);
    boolean upgraded = typeLoader.loadType(type, toLoadDependency);
    ToscaContext.get().resetDependencies(typeLoader.getLoadedDependencies());
    // Validate does not induce missing types
    try {
        this.checkForMissingTypes(topology);
    } catch (NotFoundException e) {
        // Revert changes made to the Context then throw.
        ToscaContext.get().resetDependencies(topology.getDependencies());
        throw new VersionConflictException("Adding the type [" + element.getId() + "] from archive [" + element.getArchiveName() + ":" + element.getArchiveVersion() + "] changes the topology dependencies and induces missing types. " + "Try with another version instead. Not found : [" + e.getMessage() + "].", e);
    }
    topology.setDependencies(typeLoader.getLoadedDependencies());
    // recover the topology if needed
    if (upgraded) {
        recover(topology, toLoadDependency);
    }
    return ToscaContext.getOrFail((Class<T>) element.getClass(), type);
}
Also used : VersionConflictException(alien4cloud.exception.VersionConflictException) ToscaTypeLoader(alien4cloud.tosca.container.ToscaTypeLoader) NotFoundException(alien4cloud.exception.NotFoundException) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 5 with ToscaTypeLoader

use of alien4cloud.tosca.container.ToscaTypeLoader in project alien4cloud by alien4cloud.

the class LocationResourceService method refreshDependencies.

private void refreshDependencies(Location location) {
    ToscaTypeLoader toscaTypeLoader = new ToscaTypeLoader(csarDependencyLoader);
    loadResourcesTypes(getResourcesTemplates(location.getId()), location, toscaTypeLoader);
    loadResourcesTypes(getPoliciesResourcesTemplates((location.getId())), location, toscaTypeLoader);
    location.setDependencies(toscaTypeLoader.getLoadedDependencies());
    // ALWAYS add native dependencies
    location.getDependencies().addAll(pluginArchiveIndexer.getNativeDependencies(orchestratorService.getOrFail(location.getOrchestratorId()), location));
}
Also used : ToscaTypeLoader(alien4cloud.tosca.container.ToscaTypeLoader)

Aggregations

ToscaTypeLoader (alien4cloud.tosca.container.ToscaTypeLoader)6 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)2 NotFoundException (alien4cloud.exception.NotFoundException)1 VersionConflictException (alien4cloud.exception.VersionConflictException)1 ICsarDependencyLoader (org.alien4cloud.tosca.catalog.index.ICsarDependencyLoader)1 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)1 PolicyTemplate (org.alien4cloud.tosca.model.templates.PolicyTemplate)1 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)1 SubstitutionTarget (org.alien4cloud.tosca.model.templates.SubstitutionTarget)1 NodeType (org.alien4cloud.tosca.model.types.NodeType)1 PolicyType (org.alien4cloud.tosca.model.types.PolicyType)1 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)1 Before (org.junit.Before)1