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);
}
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());
}
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());
}
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);
}
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));
}
Aggregations