Search in sources :

Example 26 with CSARDependency

use of org.alien4cloud.tosca.model.CSARDependency in project alien4cloud by alien4cloud.

the class ToscaArchiveParser method initDependencyBeanFromToscaMeta.

private CsarDependenciesBean initDependencyBeanFromToscaMeta(ToscaMeta toscaMeta) {
    CsarDependenciesBean csarDependenciesBean = new CsarDependenciesBean();
    csarDependenciesBean.setSelf(new CSARDependency(toscaMeta.getName(), toscaMeta.getVersion()));
    return csarDependenciesBean;
}
Also used : CsarDependenciesBean(org.alien4cloud.tosca.model.CsarDependenciesBean) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 27 with CSARDependency

use of org.alien4cloud.tosca.model.CSARDependency in project alien4cloud by alien4cloud.

the class NodeTemplateUtilsTest method getCapabilityByTypeTest.

@Test
public void getCapabilityByTypeTest() {
    NodeTemplate nodeTemplate = new NodeTemplate();
    Capability nodeCapability = new Capability("org.alien4cloud.capabilities.SampleCapability", null);
    nodeTemplate.setCapabilities(Maps.newHashMap("test", nodeCapability));
    // if the capability type exactly equals then no tosca context and request is required
    Capability capability = getCapabilityByType(nodeTemplate, "org.alien4cloud.capabilities.SampleCapability");
    assertSame(nodeCapability, capability);
    // if the capability derives from parent type then a TOSCA context and query is required to fetch the type.
    CapabilityType capabilityType = new CapabilityType();
    capabilityType.setElementId("org.alien4cloud.capabilities.SampleCapability");
    capabilityType.setDerivedFrom(Lists.newArrayList("org.alien4cloud.capabilities.TestCapability"));
    Mockito.reset(csarRepositorySearchService);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("org.alien4cloud.capabilities.SampleCapability"), Mockito.any(Set.class))).thenReturn(capabilityType);
    capability = toscaContextualAspect.execInToscaContext(() -> getCapabilityByType(nodeTemplate, "org.alien4cloud.capabilities.TestCapability"), false, Sets.newHashSet(new CSARDependency("org.alien4cloud.testArchive", "1.0.0-SNAPSHOT")));
    assertSame(nodeCapability, capability);
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Set(java.util.Set) Capability(org.alien4cloud.tosca.model.templates.Capability) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Test(org.junit.Test)

Example 28 with CSARDependency

use of org.alien4cloud.tosca.model.CSARDependency in project alien4cloud by alien4cloud.

the class NodeTemplateUtilsTest method getMissingCapabilityByTypeTest.

@Test
public void getMissingCapabilityByTypeTest() {
    NodeTemplate nodeTemplate = new NodeTemplate();
    Capability nodeCapability = new Capability("org.alien4cloud.capabilities.SampleCapability", null);
    nodeTemplate.setCapabilities(Maps.newHashMap("test", nodeCapability));
    // if the capability derives from parent type then a TOSCA context and query is required to fetch the type.
    CapabilityType capabilityType = new CapabilityType();
    capabilityType.setElementId("org.alien4cloud.capabilities.SampleCapability");
    capabilityType.setDerivedFrom(Lists.newArrayList("org.alien4cloud.capabilities.TestCapability"));
    Mockito.reset(csarRepositorySearchService);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("org.alien4cloud.capabilities.SampleCapability"), Mockito.any(Set.class))).thenReturn(capabilityType);
    Capability capability = toscaContextualAspect.execInToscaContext(() -> getCapabilityByType(nodeTemplate, "org.alien4cloud.capabilities.Unknown"), false, Sets.newHashSet(new CSARDependency("org.alien4cloud.testArchive", "1.0.0-SNAPSHOT")));
    assertNull(capability);
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Set(java.util.Set) Capability(org.alien4cloud.tosca.model.templates.Capability) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Test(org.junit.Test)

Example 29 with CSARDependency

use of org.alien4cloud.tosca.model.CSARDependency in project alien4cloud by alien4cloud.

the class DeploymentTopologyDTOBuilder method enrichSubstitutionTypesWithServicesDependencies.

/**
 * Enrich {@link LocationResourceTypes} adding types coming from on demand service resources.
 */
private void enrichSubstitutionTypesWithServicesDependencies(Collection<LocationResourceTemplate> resourceTemplates, LocationResourceTypes locationResourceTypes) {
    Set<String> serviceTypes = Sets.newHashSet();
    Set<CSARDependency> dependencies = Sets.newHashSet();
    for (LocationResourceTemplate resourceTemplate : resourceTemplates) {
        if (resourceTemplate.isService()) {
            String serviceId = resourceTemplate.getId();
            ServiceResource serviceResource = serviceResourceService.getOrFail(serviceId);
            NodeType serviceType = ToscaContext.get(NodeType.class, serviceResource.getNodeInstance().getNodeTemplate().getType());
            if (serviceType == null || !serviceType.getArchiveVersion().equals(serviceResource.getNodeInstance().getTypeVersion())) {
                serviceType = toscaTypeSearchService.findOrFail(NodeType.class, serviceResource.getNodeInstance().getNodeTemplate().getType(), serviceResource.getNodeInstance().getTypeVersion());
            }
            dependencies.addAll(csarDependencyLoader.getDependencies(serviceType.getArchiveName(), serviceType.getArchiveVersion()));
            dependencies.add(new CSARDependency(serviceType.getArchiveName(), serviceType.getArchiveVersion()));
            serviceTypes.add(serviceResource.getNodeInstance().getNodeTemplate().getType());
        }
    }
    locationResourceService.fillLocationResourceTypes(serviceTypes, locationResourceTypes, dependencies);
}
Also used : PolicyLocationResourceTemplate(alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) ServiceResource(alien4cloud.model.service.ServiceResource) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 30 with CSARDependency

use of org.alien4cloud.tosca.model.CSARDependency in project alien4cloud by alien4cloud.

the class PluginArchiveIndexer method getArchivesToIndex.

/**
 * From all exposed plugin archives of the location, get the one that are not yet indexed
 *
 * @param orchestrator
 * @param location
 * @return an object of type {@link ArchiveToIndex} with the indexable archives and the full list of dependencies
 */
private ArchiveToIndex getArchivesToIndex(Orchestrator orchestrator, Location location) {
    Set<CSARDependency> dependencies = Sets.newHashSet();
    IOrchestratorPlugin orchestratorInstance = (IOrchestratorPlugin) orchestratorPluginService.getOrFail(orchestrator.getId());
    ILocationConfiguratorPlugin configuratorPlugin = orchestratorInstance.getConfigurator(location.getInfrastructureType());
    List<PluginArchive> allPluginArchives = configuratorPlugin.pluginArchives();
    Set<PluginArchive> archivesToIndex = Sets.newHashSet();
    for (PluginArchive pluginArchive : safe(allPluginArchives)) {
        ArchiveRoot archive = pluginArchive.getArchive();
        Csar csar = csarService.get(archive.getArchive().getName(), archive.getArchive().getVersion());
        String lastParsedHash = null;
        if (csar == null) {
            // the archive does not exist into the repository: should be indexed
            lastParsedHash = archive.getArchive().getHash();
            archivesToIndex.add(pluginArchive);
        } else {
            // Else, just take the hash
            lastParsedHash = csar.getHash();
        }
        if (archive.getArchive().getDependencies() != null) {
            dependencies.addAll(archive.getArchive().getDependencies());
        }
        dependencies.add(new CSARDependency(archive.getArchive().getName(), archive.getArchive().getVersion(), lastParsedHash));
    }
    return new ArchiveToIndex(dependencies, archivesToIndex);
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ILocationConfiguratorPlugin(alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin) PluginArchive(alien4cloud.orchestrators.plugin.model.PluginArchive) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Aggregations

CSARDependency (org.alien4cloud.tosca.model.CSARDependency)50 Csar (org.alien4cloud.tosca.model.Csar)16 Test (org.junit.Test)11 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)8 Set (java.util.Set)7 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)6 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)6 ServiceResource (alien4cloud.model.service.ServiceResource)5 Capability (org.alien4cloud.tosca.model.templates.Capability)5 Topology (org.alien4cloud.tosca.model.templates.Topology)5 NodeType (org.alien4cloud.tosca.model.types.NodeType)5 NotFoundException (alien4cloud.exception.NotFoundException)4 ParsingError (alien4cloud.tosca.parser.ParsingError)4 HashSet (java.util.HashSet)4 CsarDependenciesBean (org.alien4cloud.tosca.model.CsarDependenciesBean)4 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)3 ParsingException (alien4cloud.tosca.parser.ParsingException)3 VersionConflictException (alien4cloud.exception.VersionConflictException)2 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)2 Location (alien4cloud.model.orchestrators.locations.Location)2