Search in sources :

Example 11 with CSARDependency

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

the class CloudServiceArchiveController method addDependency.

@ApiOperation(value = "Add dependency to the csar with given id.")
@RequestMapping(value = "/{csarId:.+?}/dependencies", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
@Deprecated
public RestResponse<Boolean> addDependency(@PathVariable String csarId, @Valid @RequestBody CSARDependency dependency) {
    Csar csar = csarService.getOrFail(csarId);
    csarAuthorizationFilter.checkWriteAccess(csar);
    Set<CSARDependency> existingDependencies = csar.getDependencies();
    if (existingDependencies == null) {
        existingDependencies = Sets.newHashSet();
        csar.setDependencies(existingDependencies);
    }
    boolean couldBeSaved = existingDependencies.add(dependency);
    csarDAO.save(csar);
    return RestResponseBuilder.<Boolean>builder().data(couldBeSaved).build();
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with CSARDependency

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

the class ToscaParserSimpleProfileAlien130Test method testImportDependency.

@Test
public void testImportDependency() throws FileNotFoundException, ParsingException {
    Csar csar = new Csar("tosca-normative-types", "1.0.0-SNAPSHOT-wd03");
    Mockito.when(csarRepositorySearchService.getArchive(csar.getName(), csar.getVersion())).thenReturn(csar);
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-import-dependency.yml"));
    Mockito.verify(csarRepositorySearchService).getArchive(csar.getName(), csar.getVersion());
    assertNoBlocker(parsingResult);
    ArchiveRoot archiveRoot = parsingResult.getResult();
    assertNotNull(archiveRoot.getArchive());
    assertNotNull(archiveRoot.getArchive().getDependencies());
    Assert.assertEquals(1, archiveRoot.getArchive().getDependencies().size());
    Assert.assertEquals(new CSARDependency(csar.getName(), csar.getVersion()), archiveRoot.getArchive().getDependencies().iterator().next());
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Test(org.junit.Test)

Example 13 with CSARDependency

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

the class LocalRepositoryImpl method getArchive.

@Override
public Csar getArchive(String archiveName, String archiveVersion) {
    CSARDependency dependency = new CSARDependency(archiveName, archiveVersion);
    ArchiveRoot root = parse(dependency).getResult();
    return root == null ? null : root.getArchive();
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 14 with CSARDependency

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

the class ToscaTypeSearchService method getDependencyQuery.

/**
 * Build an elasticsearch query to get data tosca elements based on a set of dependencies.
 *
 * @param dependencies The set of dependencies.
 * @param keyValueFilters List of key1, value1, key2, value2 to add term filters to the query for each dependency.
 * @return
 */
private BoolQueryBuilder getDependencyQuery(Set<CSARDependency> dependencies, String... keyValueFilters) {
    BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
    for (CSARDependency dependency : dependencies) {
        BoolQueryBuilder dependencyQuery = QueryBuilders.boolQuery();
        dependencyQuery.must(QueryBuilders.termQuery("archiveName", dependency.getName())).must(QueryBuilders.termQuery("archiveVersion", dependency.getVersion()));
        if (keyValueFilters != null) {
            for (int i = 0; i < keyValueFilters.length; i += 2) {
                dependencyQuery.must(QueryBuilders.termQuery(keyValueFilters[i], keyValueFilters[i + 1]));
            }
        }
        boolQueryBuilder.should(dependencyQuery);
    }
    return boolQueryBuilder;
}
Also used : BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 15 with CSARDependency

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

the class RecoverTopologyProcessor method process.

@Override
public void process(Csar csar, Topology topology, RecoverTopologyOperation operation) {
    checkOperation(operation, topology);
    // process every recovery operation
    // we need a new context here, as we want to have fresh types from elasticsearch
    recoveryHelperService.processRecoveryOperations(topology, operation.getRecoveringOperations());
    // make sure we also synch the dependencies and the caches types
    for (CSARDependency updatedDependency : AlienUtils.safe(operation.getUpdatedDependencies())) {
        ToscaContext.get().updateDependency(updatedDependency);
    }
    // TODO passing to this function the processRecoveryOperations ToscaContext should help reducing ES requests
    topologyService.rebuildDependencies(topology);
}
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