Search in sources :

Example 1 with Location

use of alien4cloud.model.orchestrators.locations.Location in project yorc-a4c-plugin by ystia.

the class DeployTask method buildZip.

/**
 * Create the zip for yorc, with a modified yaml and all needed archives.
 * Assumes a file original.yml exists in the current directory
 * @param ctx all needed information about the deployment
 * @throws IOException
 */
private void buildZip(PaaSTopologyDeploymentContext ctx) throws IOException {
    // Check location
    int location = LOC_OPENSTACK;
    Location loc = ctx.getLocations().get("_A4C_ALL");
    Set<CSARDependency> locdeps = loc.getDependencies();
    for (CSARDependency dep : locdeps) {
        if (dep.getName().contains("kubernetes")) {
            location = LOC_KUBERNETES;
            break;
        }
        if (dep.getName().contains("slurm")) {
            location = LOC_SLURM;
            break;
        }
        if (dep.getName().contains("aws")) {
            location = LOC_AWS;
            break;
        }
    }
    // Final zip file will be named topology.zip
    final File zip = new File("topology.zip");
    final OutputStream out = new FileOutputStream(zip);
    final ZipOutputStream zout = new ZipOutputStream(out);
    final Closeable res = zout;
    final int finalLocation = location;
    this.ctx.getDeploymentTopology().getDependencies().forEach(d -> {
        if (!"tosca-normative-types".equals(d.getName())) {
            Csar csar = csarRepoSearchService.getArchive(d.getName(), d.getVersion());
            if (CSARSource.ORCHESTRATOR != CSARSource.valueOf(csar.getImportSource())) {
                try {
                    csar2zip(zout, csar, finalLocation);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
    });
    // Copy overwritten artifacts for each node
    PaaSTopology ptopo = ctx.getPaaSTopology();
    for (PaaSNodeTemplate node : ptopo.getAllNodes().values()) {
        copyArtifacts(node, zout);
    }
    String topoFileName = "topology.yml";
    // Copy modified topology
    createZipEntries(topoFileName, zout);
    // Get the yaml of the application as built by from a4c
    DeploymentTopology dtopo = ctx.getDeploymentTopology();
    Csar myCsar = new Csar(ctx.getDeploymentPaaSId(), dtopo.getArchiveVersion());
    myCsar.setToscaDefinitionsVersion(ToscaParser.LATEST_DSL);
    String yaml = orchestrator.getToscaTopologyExporter().getYaml(myCsar, dtopo, true);
    zout.write(yaml.getBytes(Charset.forName("UTF-8")));
    zout.closeEntry();
    res.close();
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) PaaSTopology(alien4cloud.paas.model.PaaSTopology) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Closeable(java.io.Closeable) ZipException(java.util.zip.ZipException) YorcRestException(org.ystia.yorc.alien4cloud.plugin.rest.YorcRestException) ParsingException(alien4cloud.tosca.parser.ParsingException) IOException(java.io.IOException) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Location(alien4cloud.model.orchestrators.locations.Location)

Example 2 with Location

use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.

the class AlienContextVariablesTest method setUp.

@Before
public void setUp() throws Exception {
    alienContextVariables = new AlienContextVariables();
    Application app = new Application();
    app.setTags(Arrays.asList(new Tag("tagName", "tagValue"), new Tag("yolo", "oloy")));
    app.setMetaProperties(ImmutableMap.of("meta1", "meta1 value", "meta2", "meta2 value"));
    alienContextVariables.setApplication(app);
    Location location = new Location();
    location.setMetaProperties(ImmutableMap.of("loc_meta1", "meta1 value", "loc_meta2", "meta2 value"));
    alienContextVariables.setLocation(location);
}
Also used : Tag(alien4cloud.model.common.Tag) Application(alien4cloud.model.application.Application) Location(alien4cloud.model.orchestrators.locations.Location) Before(org.junit.Before)

Example 3 with Location

use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.

the class LocationResourceService method setTemplateCapabilityProperty.

private void setTemplateCapabilityProperty(LocationResourceTemplate resourceTemplate, String capabilityName, String propertyName, Object propertyValue) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException {
    Location location = locationService.getOrFail(resourceTemplate.getLocationId());
    NodeType resourceType = csarRepoSearchService.getRequiredElementInDependencies(NodeType.class, resourceTemplate.getTemplate().getType(), location.getDependencies());
    Capability capability = getOrFailCapability(resourceTemplate.getTemplate(), capabilityName);
    CapabilityDefinition capabilityDefinition = getOrFailCapabilityDefinition(resourceType, capabilityName);
    CapabilityType capabilityType = csarRepoSearchService.getRequiredElementInDependencies(CapabilityType.class, capabilityDefinition.getType(), location.getDependencies());
    PropertyDefinition propertyDefinition = getOrFailCapabilityPropertyDefinition(capabilityType, propertyName);
    propertyService.setCapabilityPropertyValue(location.getDependencies(), capability, propertyDefinition, propertyName, propertyValue);
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Location(alien4cloud.model.orchestrators.locations.Location)

Example 4 with Location

use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.

the class LocationResourceService method deleteResourceTemplate.

/*
     * (non-Javadoc)
     * 
     * @see alien4cloud.orchestrators.locations.services.ILocationResourceService#deleteResourceTemplate(Class, String)
     */
@Override
public void deleteResourceTemplate(String resourceId) {
    AbstractLocationResourceTemplate resourceTemplate = getOrFail(resourceId);
    Location location = locationService.getOrFail(resourceTemplate.getLocationId());
    alienDAO.delete(resourceTemplate.getClass(), resourceId);
    refreshDependencies(location);
    alienDAO.save(location);
}
Also used : AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) Location(alien4cloud.model.orchestrators.locations.Location)

Example 5 with Location

use of alien4cloud.model.orchestrators.locations.Location 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)

Aggregations

Location (alien4cloud.model.orchestrators.locations.Location)80 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)31 ApiOperation (io.swagger.annotations.ApiOperation)30 List (java.util.List)28 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)28 Audit (alien4cloud.audit.annotation.Audit)21 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)15 LocationService (alien4cloud.orchestrators.locations.services.LocationService)13 Set (java.util.Set)13 Collectors (java.util.stream.Collectors)13 Application (alien4cloud.model.application.Application)12 AbstractLocationResourceTemplate (alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate)12 RestResponse (alien4cloud.rest.model.RestResponse)12 RestResponseBuilder (alien4cloud.rest.model.RestResponseBuilder)12 GroupDTO (alien4cloud.rest.orchestrator.model.GroupDTO)12 UserDTO (alien4cloud.rest.orchestrator.model.UserDTO)12 Resource (javax.annotation.Resource)12 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)11 ResourcePermissionService (alien4cloud.authorization.ResourcePermissionService)11 ApplicationEnvironmentAuthorizationUpdateRequest (alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationUpdateRequest)11