Search in sources :

Example 41 with CSARDependency

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

the class ServiceResourceServiceTest method testReportArchiveUsage.

@Test
public void testReportArchiveUsage() {
    ServiceResource serviceResource = new ServiceResource();
    serviceResource.setId("service1");
    serviceResource.setName("service name 1");
    serviceResource.setDependency(new CSARDependency("org.alien4cloud.archives:my-archive", "1.0.0-SNAPSHOT"));
    alienDao.save(serviceResource);
    ArchiveUsageRequestEvent archiveUsageRequestEvent = new ArchiveUsageRequestEvent(this, "org.alien4cloud.archives:my-archive", "1.0.0-SNAPSHOT");
    serviceResourceService.reportArchiveUsage(archiveUsageRequestEvent);
    Assert.assertEquals(1, archiveUsageRequestEvent.getUsages().size());
    Assert.assertEquals("service1", archiveUsageRequestEvent.getUsages().get(0).getResourceId());
    Assert.assertEquals("serviceresource", archiveUsageRequestEvent.getUsages().get(0).getResourceType());
    Assert.assertEquals("service name 1", archiveUsageRequestEvent.getUsages().get(0).getResourceName());
    archiveUsageRequestEvent = new ArchiveUsageRequestEvent(this, "org.alien4cloud.archives:other-archive", "1.0.0-SNAPSHOT");
    serviceResourceService.reportArchiveUsage(archiveUsageRequestEvent);
    Assert.assertEquals(0, archiveUsageRequestEvent.getUsages().size());
    archiveUsageRequestEvent = new ArchiveUsageRequestEvent(this, "org.alien4cloud.archives:my-archive", "1.0.1-SNAPSHOT");
    serviceResourceService.reportArchiveUsage(archiveUsageRequestEvent);
    Assert.assertEquals(0, archiveUsageRequestEvent.getUsages().size());
}
Also used : ArchiveUsageRequestEvent(org.alien4cloud.tosca.catalog.events.ArchiveUsageRequestEvent) ServiceResource(alien4cloud.model.service.ServiceResource) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Test(org.junit.Test)

Example 42 with CSARDependency

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

the class CrudCSARSStepDefinition method The_csar_version_does_not_depend_on_csar_version.

@Then("^The CSAR \"([^\"]*)\" version \"([^\"]*)\" does not have a dependency to \"([^\"]*)\" version \"([^\"]*)\"$")
public void The_csar_version_does_not_depend_on_csar_version(String csarName, String csarVersion, String dependencyName, String dependencyVersion) throws Throwable {
    String response = Context.getRestClientInstance().get("/rest/v1/csars/" + csarName + ":" + csarVersion);
    CsarInfoDTO csar = JsonUtil.read(response, CsarInfoDTO.class).getData();
    Assert.assertFalse(csar.getCsar().getDependencies().contains(new CSARDependency(dependencyName, dependencyVersion)));
}
Also used : CsarInfoDTO(alien4cloud.rest.csar.CsarInfoDTO) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Then(cucumber.api.java.en.Then)

Example 43 with CSARDependency

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

the class CrudCSARSStepDefinition method I_add_a_dependency_with_name_version_to_the_CSAR_with_name_version.

@When("^I add a dependency with name \"([^\"]*)\" version \"([^\"]*)\" to the CSAR with name \"([^\"]*)\" version \"([^\"]*)\"$")
public void I_add_a_dependency_with_name_version_to_the_CSAR_with_name_version(String dependencyName, String dependencyVersion, String csarName, String csarVersion) throws Throwable {
    CSARDependency dependency = new CSARDependency(dependencyName, dependencyVersion);
    Context.getInstance().registerRestResponse(Context.getRestClientInstance().postJSon("/rest/v1/csars/" + csarName + ":" + csarVersion + "-SNAPSHOT" + "/dependencies", JsonUtil.toString(dependency)));
}
Also used : CSARDependency(org.alien4cloud.tosca.model.CSARDependency) When(cucumber.api.java.en.When)

Example 44 with CSARDependency

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

the class ToscaContextualAspect method findDependencies.

private Set<CSARDependency> findDependencies(Object[] args) {
    for (Object arg : args) {
        if (arg instanceof Topology) {
            return ((Topology) arg).getDependencies();
        }
        if (arg instanceof Set) {
            Set set = (Set) arg;
            if (set.size() > 0 && set.iterator().next() instanceof CSARDependency) {
                return (Set<CSARDependency>) arg;
            }
        }
        if (arg instanceof AbstractToscaType) {
            AbstractToscaType type = ((AbstractToscaType) arg);
            Csar csar = csarRepositorySearchService.getArchive(type.getArchiveName(), type.getArchiveVersion());
            if (csar == null) {
                throw new NotFoundException("Unable to find dependencies from type as it's archive cannot be found in the repository.");
            }
            Set<CSARDependency> dependencies = csar.getDependencies() == null ? Sets.newHashSet() : csar.getDependencies();
            dependencies.add(new CSARDependency(type.getArchiveName(), type.getArchiveVersion()));
            return dependencies;
        }
    }
    return Sets.<CSARDependency>newHashSet();
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Set(java.util.Set) AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) NotFoundException(alien4cloud.exception.NotFoundException) Topology(org.alien4cloud.tosca.model.templates.Topology) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 45 with CSARDependency

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

the class LocalRepositoryImpl method getElementInDependencies.

@Override
public <T extends AbstractToscaType> T getElementInDependencies(Class<T> elementClass, String elementId, Set<CSARDependency> dependencies) {
    if (recursiveCall.get() == null) {
        recursiveCall.set(true);
    } else {
        return null;
    }
    // ensure that dependencies are loaded in the ToscaContext
    for (CSARDependency dependency : dependencies) {
        // parse and register the archive from local repository.
        parseAndRegister(dependency);
    }
    T element = ToscaContext.get(elementClass, elementId);
    recursiveCall.remove();
    return element;
}
Also used : CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

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