Search in sources :

Example 6 with CSARDependency

use of org.alien4cloud.tosca.model.CSARDependency 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 7 with CSARDependency

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

the class ToscaSerializerTest method simpleTest.

@Ignore
@Test
public void simpleTest() throws IOException, URISyntaxException {
    Topology topology = new Topology();
    topology.setDependencies(new HashSet<CSARDependency>());
    topology.getDependencies().add(new CSARDependency("name1", "1.0"));
    topology.getDependencies().add(new CSARDependency("name2", "2.0"));
    topology.setInputs(new HashMap<String, PropertyDefinition>());
    PropertyDefinition pd1 = new PropertyDefinition();
    pd1.setType("string");
    pd1.setConstraints(getConstraintList());
    pd1.setDescription("A description");
    topology.getInputs().put("input1", pd1);
    PropertyDefinition pd2 = new PropertyDefinition();
    pd2.setType("integer");
    pd2.setRequired(false);
    pd2.setDefault(new ScalarPropertyValue("10"));
    topology.getInputs().put("input2", pd2);
    PropertyDefinition pd3 = new PropertyDefinition();
    pd3.setType("map");
    pd3.setRequired(false);
    PropertyDefinition entrySchema = new PropertyDefinition();
    entrySchema.setType("integer");
    pd3.setEntrySchema(entrySchema);
    topology.getInputs().put("input3", pd3);
    topology.setNodeTemplates(new HashMap<String, NodeTemplate>());
    topology.getNodeTemplates().put("node1", new NodeTemplate());
    topology.getNodeTemplates().get("node1").setType("the.node.Type");
    topology.getNodeTemplates().get("node1").setProperties(buildSamplePropertyValueMap());
    topology.getNodeTemplates().get("node1").setRelationships(new HashMap<String, RelationshipTemplate>());
    topology.getNodeTemplates().get("node1").getRelationships().put("hostedOn", new RelationshipTemplate());
    topology.getNodeTemplates().get("node1").getRelationships().get("hostedOn").setTarget("compute2");
    topology.getNodeTemplates().get("node1").getRelationships().get("hostedOn").setRequirementType("capabilities.Capa");
    topology.getNodeTemplates().get("node1").getRelationships().get("hostedOn").setRequirementName("host");
    topology.getNodeTemplates().get("node1").getRelationships().get("hostedOn").setType("relationship.Rel");
    topology.getNodeTemplates().get("node1").getRelationships().get("hostedOn").setProperties(buildSamplePropertyValueMap());
    topology.getNodeTemplates().get("node1").setCapabilities(new HashMap<String, Capability>());
    Capability capability = new Capability();
    capability.setProperties(buildSamplePropertyValueMap());
    topology.getNodeTemplates().get("node1").getCapabilities().put("capa1", capability);
    // this capability should not appear
    topology.getNodeTemplates().get("node1").getCapabilities().put("capa2", new Capability());
    topology.getNodeTemplates().get("node1").setArtifacts(new HashMap<String, DeploymentArtifact>());
    DeploymentArtifact da = new DeploymentArtifact();
    da.setArtifactName("artifact.war");
    da.setArtifactRef("010203904872876723");
    da.setArtifactType("artifacttypes.Artifact");
    topology.getNodeTemplates().get("node1").getArtifacts().put("artifact1", da);
    topology.setOutputProperties(new HashMap<String, Set<String>>());
    topology.getOutputProperties().put("node1", Sets.newHashSet("prop1", "prop2"));
    topology.setOutputAttributes(new HashMap<String, Set<String>>());
    topology.getOutputAttributes().put("node1", Sets.newHashSet("att1", "att2"));
    Map<String, Object> velocityCtx = new HashMap<String, Object>();
    velocityCtx.put("topology", topology);
    velocityCtx.put("template_name", "template-id");
    velocityCtx.put("template_version", "1.0.0-SNAPSHOT");
    velocityCtx.put("template_author", "Foo Bar");
    velocityCtx.put("application_description", "Here is a \nmultiline description");
    StringWriter writer = new StringWriter();
    VelocityUtil.generate("org/alien4cloud/tosca/exporter/topology-alien_dsl_1_4_0.yml.vm", writer, velocityCtx);
    System.out.println(writer.toString());
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Capability(org.alien4cloud.tosca.model.templates.Capability) HashMap(java.util.HashMap) Topology(org.alien4cloud.tosca.model.templates.Topology) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) StringWriter(java.io.StringWriter) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with CSARDependency

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

the class LocationResourceService method updateLocationDependencies.

private Location updateLocationDependencies(String locationId, String archiveName, String archiveVersion) {
    Location location = locationService.getOrFail(locationId);
    // If an archive is specified, update the location dependencies accordingly. Dependencies are in a Set so there is no duplication issue.
    if (!(StringUtils.isEmpty(archiveName) && StringUtils.isEmpty(archiveVersion))) {
        Optional.ofNullable(csarRepoSearchService.getArchive(archiveName, archiveVersion)).map(Csar::getDependencies).ifPresent(csarDependencies -> location.getDependencies().addAll(csarDependencies));
        // Add the archive as dependency too
        final CSARDependency archive = new CSARDependency(archiveName, archiveVersion);
        location.getDependencies().add(archive);
    }
    return location;
}
Also used : Location(alien4cloud.model.orchestrators.locations.Location) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 9 with CSARDependency

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

the class LocationService method createLocation.

private void createLocation(Orchestrator orchestrator, Location location, String infrastructureType) {
    ensureNameUnicityAndSave(location);
    // TODO checks that the infrastructure type is valid
    location.setInfrastructureType(infrastructureType);
    // TODO add User and Group managed by the Orchestrator security
    Set<CSARDependency> dependencies = locationArchiveIndexer.indexLocationArchives(orchestrator, location);
    location.setDependencies(dependencies);
    // initialize meta properties
    location.setMetaProperties(Maps.<String, String>newHashMap());
    // add existing meta properties to the cloud
    GetMultipleDataResult<MetaPropConfiguration> result = alienDAO.find(MetaPropConfiguration.class, singleKeyFilter("target", MetaPropertyTarget.LOCATION), Integer.MAX_VALUE);
    for (MetaPropConfiguration element : result.getData()) {
        if (Objects.equals(element.getTarget(), MetaPropertyTarget.LOCATION)) {
            // we only support string values for meta properties
            PropertyUtil.setScalarDefaultValueOrNull(location.getMetaProperties(), element.getId(), element.getDefault());
            log.debug("Added meta property [ {} ] to the new location [ {} ] ", element.getName(), location.getName());
        }
    }
    // save the new location
    alienDAO.save(location);
    try {
        autoConfigure(orchestrator, location);
    } catch (UnsupportedOperationException e) {
    // do nothing
    }
    // We call the LocationRessourceService to check the dependencies
    try {
        locationResourceService.getLocationResourcesFromOrchestrator(location);
    } catch (NotFoundException e) {
        // WARN: FIXME we load orch twice !!!!!!!!!!!!!!!!!!!!!!!!!
        delete(orchestrator.getId(), location.getId());
        throw new MissingCSARDependenciesException(e.getMessage());
    }
}
Also used : MetaPropConfiguration(alien4cloud.model.common.MetaPropConfiguration) NotFoundException(alien4cloud.exception.NotFoundException) MissingCSARDependenciesException(alien4cloud.exception.MissingCSARDependenciesException) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 10 with CSARDependency

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

the class LocationResourceGeneratorService method generateComputeFromImageAndFlavor.

/**
 * Generate resources of type compute given a set of images and flavors
 *
 * @param imageContext
 * @param flavorContext
 * @param linuxComputeContext
 * @param windowsComputeContext
 * @param resourceAccessor
 * @return
 */
public List<LocationResourceTemplate> generateComputeFromImageAndFlavor(ImageFlavorContext imageContext, ImageFlavorContext flavorContext, ComputeContext linuxComputeContext, ComputeContext windowsComputeContext, ILocationResourceAccessor resourceAccessor) {
    List<LocationResourceTemplate> images = imageContext.getTemplates();
    List<LocationResourceTemplate> flavors = flavorContext.getTemplates();
    Set<CSARDependency> dependencies = resourceAccessor.getDependencies();
    List<LocationResourceTemplate> generated = Lists.newArrayList();
    for (LocationResourceTemplate image : images) {
        for (LocationResourceTemplate flavor : flavors) {
            String defaultComputeName = generateDefaultName(image, flavor);
            int count = 0;
            ComputeContext computeContext = isWindowsImage(image) && windowsComputeContext != null ? windowsComputeContext : linuxComputeContext;
            for (NodeType indexedNodeType : computeContext.getNodeTypes()) {
                String name = StringUtils.isNotBlank(computeContext.getGeneratedNamePrefix()) ? computeContext.getGeneratedNamePrefix() : defaultComputeName;
                if (count > 0) {
                    name = name + "_" + count;
                }
                NodeTemplate node = templateBuilder.buildNodeTemplate(dependencies, indexedNodeType);
                // set the imageId
                node.getProperties().put(computeContext.getImageIdPropertyName(), image.getTemplate().getProperties().get(imageContext.getIdPropertyName()));
                // set the flavorId
                node.getProperties().put(computeContext.getFlavorIdPropertyName(), flavor.getTemplate().getProperties().get(flavorContext.getIdPropertyName()));
                // copy os and host capabilities properties
                copyCapabilityBasedOnTheType(image.getTemplate(), node, "os");
                copyCapabilityBasedOnTheType(flavor.getTemplate(), node, "host");
                LocationResourceTemplate resource = new LocationResourceTemplate();
                resource.setService(false);
                resource.setTemplate(node);
                resource.setName(name);
                count++;
                generated.add(resource);
            }
        }
    }
    return generated;
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) 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