Search in sources :

Example 46 with CSARDependency

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

the class NodeTemplateUtilsTest method getCapabilityByTypeOrFailTest.

@Test
public void getCapabilityByTypeOrFailTest() {
    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 = getCapabilityByTypeOrFail(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(() -> getCapabilityByTypeOrFail(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 47 with CSARDependency

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

the class NodeTemplateUtilsTest method getMissingCapabilityByTypeOrFailTest.

@Test(expected = NotFoundException.class)
public void getMissingCapabilityByTypeOrFailTest() {
    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(() -> getCapabilityByTypeOrFail(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 48 with CSARDependency

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

the class ToscaDefinitionVersionParser method parse.

@Override
public String parse(Node node, ParsingContextExecution context) {
    ArchiveRoot archiveRoot = (ArchiveRoot) context.getParent();
    String toscaDefinitionVersion = ParserUtils.getScalar(node, context);
    if (toscaDefinitionVersion != null) {
        CSARDependency dependency = ToscaNormativeImports.IMPORTS.get(toscaDefinitionVersion);
        if (dependency != null) {
            // File based parsing implementation of the requirement of normative types will load them from file (meaning basically that we will loop here)
            if (loadingNormative.get() == null) {
                loadingNormative.set(true);
            } else {
                return toscaDefinitionVersion;
            }
            Csar csar = ToscaContext.get().getArchive(dependency.getName(), dependency.getVersion());
            if (csar == null) {
                return toscaDefinitionVersion;
            }
            // Normative imports are automatically injected and supposed to be accessible, no specific validation is performed here.
            dependency.setHash(csar.getHash());
            ToscaContext.get().addDependency(dependency);
            Set<CSARDependency> dependencies = archiveRoot.getArchive().getDependencies();
            if (dependencies == null) {
                dependencies = new HashSet<>();
                archiveRoot.getArchive().setDependencies(dependencies);
            }
            dependencies.add(dependency);
            loadingNormative.remove();
        }
    }
    return toscaDefinitionVersion;
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 49 with CSARDependency

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

the class ImportParser method parse.

@Override
public CSARDependency parse(Node node, ParsingContextExecution context) {
    CSARDependency dependency = laxImportParser.parse(node, context);
    if (dependency == null) {
        return null;
    }
    String valueAsString = dependency.getName() + ":" + dependency.getVersion();
    String currentArchiveVersion = context.<ArchiveRoot>getRootObj().getArchive().getVersion();
    Csar csar = ToscaContext.get().getArchive(dependency.getName(), dependency.getVersion());
    log.debug("Import {} {} {}", dependency.getName(), dependency.getVersion(), csar);
    if (csar == null) {
        // error is not a blocker, as long as no type is missing we just mark it as a warning.
        context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.MISSING_DEPENDENCY, "Import definition is not valid", node.getStartMark(), "Specified dependency is not found in Alien 4 Cloud repository.", node.getEndMark(), valueAsString));
        return null;
    } else {
        if (!VersionUtil.isSnapshot(currentArchiveVersion) && VersionUtil.isSnapshot(dependency.getVersion())) {
            // the current archive is a released version but depends on a snapshot version
            context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.SNAPSHOT_DEPENDENCY, "Import definition is not valid", node.getStartMark(), "A released archive cannot depends on snapshots archives.", node.getEndMark(), valueAsString));
        }
        dependency.setHash(csar.getHash());
        ToscaContext.get().addDependency(dependency);
        return dependency;
    }
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ParsingError(alien4cloud.tosca.parser.ParsingError) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 50 with CSARDependency

use of org.alien4cloud.tosca.model.CSARDependency in project yorc-a4c-plugin by ystia.

the class ToscaExportersTest method generateImports.

@Test
public void generateImports() {
    Mockito.reset(repositorySearchService);
    Csar csar = new Csar("tosca-normative-types", "2.0.0");
    csar.setImportSource(CSARSource.ALIEN.name());
    csar.setYamlFilePath("tosca-normative-types.yaml");
    Mockito.when(repositorySearchService.getArchive("tosca-normative-types", "2.0.0")).thenReturn(csar);
    csar = new Csar("yorc-types", "1.0.0");
    csar.setImportSource(CSARSource.ORCHESTRATOR.name());
    csar.setYamlFilePath("yorc-types.yaml");
    Mockito.when(repositorySearchService.getArchive("yorc-types", "1.0.0")).thenReturn(csar);
    csar = new Csar("yorc-openstack-types", "1.0.0");
    csar.setImportSource(CSARSource.ORCHESTRATOR.name());
    csar.setYamlFilePath("yorc-openstack-types.yaml");
    Mockito.when(repositorySearchService.getArchive("yorc-openstack-types", "1.0.0")).thenReturn(csar);
    csar = new Csar("mycomponent-pub", "3.0.0");
    csar.setImportSource(CSARSource.GIT.name());
    csar.setYamlFilePath("mycomponent-pub.yaml");
    Mockito.when(repositorySearchService.getArchive("mycomponent-pub", "3.0.0")).thenReturn(csar);
    csar = new Csar("mycomponent-impl", "3.0.0");
    csar.setImportSource(CSARSource.UPLOAD.name());
    csar.setYamlFilePath("mycomponent-impl.yaml");
    Mockito.when(repositorySearchService.getArchive("mycomponent-impl", "3.0.0")).thenReturn(csar);
    // Use linked hashset here to ensure ordering
    Set<CSARDependency> deps = new LinkedHashSet<>();
    deps.add(new CSARDependency("tosca-normative-types", "2.0.0"));
    deps.add(new CSARDependency("yorc-types", "1.0.0"));
    deps.add(new CSARDependency("yorc-openstack-types", "1.0.0"));
    deps.add(new CSARDependency("mycomponent-pub", "3.0.0"));
    deps.add(new CSARDependency("mycomponent-impl", "3.0.0"));
    csar = new Csar("mytopo", "1.0.0");
    csar.setTemplateAuthor("me");
    String expected = "tosca_definitions_version: alien_dsl_2_0_0\n" + "\n" + "metadata:\n" + "  template_name: mytopo\n" + "  template_version: 1.0.0\n" + "  template_author: me\n" + "\n" + "description: \"\"\n" + "\n" + "imports:\n" + "  - <yorc-types.yml>\n" + "  - <yorc-openstack-types.yml>\n" + "  - mycomponent-pub/3.0.0/mycomponent-pub.yaml\n" + "  - mycomponent-impl/3.0.0/mycomponent-impl.yaml\n" + "\n" + "topology_template:\n" + "  node_templates:\n";
    Topology topo = new Topology();
    topo.setDependencies(deps);
    String result = toscaTopologyExporter.getYaml(csar, topo, false);
    Assert.assertEquals(expected, result);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Csar(org.alien4cloud.tosca.model.Csar) Topology(org.alien4cloud.tosca.model.templates.Topology) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Test(org.junit.Test) AbstractPluginTest(org.ystia.yorc.alien4cloud.plugin.AbstractPluginTest)

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