Search in sources :

Example 1 with Application

use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.

the class VariableExpressionService method getInEnvironmentScope.

public List<ScopeVariableExpressionDTO> getInEnvironmentScope(String varName, String applicationId, String topologyVersion, String envId) {
    Application application = applicationService.getOrFail(applicationId);
    if (StringUtils.isBlank(envId)) {
        return Arrays.stream(applicationEnvironmentService.getAuthorizedByApplicationId(applicationId)).map(env -> getVariableDef(varName, Csar.createId(env.getApplicationId(), topologyVersion), env)).collect(Collectors.toList());
    } else {
        ApplicationEnvironment env = applicationEnvironmentService.getOrFail(envId);
        AuthorizationUtil.checkAuthorizationForEnvironment(application, env);
        return Lists.newArrayList(getVariableDef(varName, Csar.createId(env.getApplicationId(), topologyVersion), env));
    }
}
Also used : Arrays(java.util.Arrays) Setter(lombok.Setter) Getter(lombok.Getter) ApplicationEnvironmentService(alien4cloud.application.ApplicationEnvironmentService) EditorFileService(org.alien4cloud.tosca.editor.EditorFileService) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Inject(javax.inject.Inject) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Map(java.util.Map) Application(alien4cloud.model.application.Application) ApplicationService(alien4cloud.application.ApplicationService) YamlParserUtil(alien4cloud.utils.YamlParserUtil) Csar(org.alien4cloud.tosca.model.Csar) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Collection(java.util.Collection) ScopeVariableExpressionDTO(org.alien4cloud.tosca.variable.ScopeVariableExpressionDTO) EqualsAndHashCode(lombok.EqualsAndHashCode) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) AuthorizationUtil(alien4cloud.security.AuthorizationUtil) List(java.util.List) EnvironmentType(alien4cloud.model.application.EnvironmentType) Variable(org.alien4cloud.tosca.variable.model.Variable) QuickFileStorageService(org.alien4cloud.tosca.variable.QuickFileStorageService) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment)

Example 2 with Application

use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.

the class EsDaoCrudTest method findByIdTest.

@Test
public void findByIdTest() throws IndexingServiceException, JsonProcessingException {
    saveDataToES(indexedNodeTypeTest);
    NodeType nt = dao.findById(NodeType.class, indexedNodeTypeTest.getId());
    assertBeanEqualsToOriginal(nt);
    nt = dao.findById(NodeType.class, indexedNodeTypeTest.getId());
    assertBeanEqualsToOriginal(nt);
    nt = dao.findById(NodeType.class, "5");
    isNull(nt);
    // findByIds
    List<NodeType> lnt = dao.findByIds(NodeType.class, new String[] { indexedNodeTypeTest.getId() });
    List<NodeType> lnt2 = dao.findByIds(NodeType.class, new String[] { indexedNodeTypeTest.getId(), "5" });
    isTrue(!lnt.isEmpty());
    isTrue(!lnt2.isEmpty());
    assertEquals(1, lnt.size());
    assertEquals(1, lnt2.size());
    nt = lnt.get(0);
    assertBeanEqualsToOriginal(nt);
    nt = lnt2.get(0);
    assertBeanEqualsToOriginal(nt);
    // findByIdsWithContext
    saveApplications();
    List<Application> apps = dao.findByIdsWithContext(Application.class, FetchContext.SUMMARY, new String[] { "1", "2", "8" });
    log.info("Search: " + JsonUtil.toString(apps));
    assertNotNull(apps);
    assertFalse(apps.isEmpty());
    assertEquals(2, apps.size());
    String[] expectedId = new String[] { "1", "2" };
    String[] ids = null;
    String[] expectedNames = new String[] { "app1", "app2" };
    String[] names = null;
    for (Application application : apps) {
        ids = ArrayUtils.add(ids, application.getId());
        names = ArrayUtils.add(names, application.getName());
        assertNull(application.getDescription());
    }
    Arrays.sort(expectedId);
    Arrays.sort(ids);
    Arrays.sort(expectedNames);
    Arrays.sort(names);
    assertArrayEquals(expectedId, ids);
    assertArrayEquals(expectedNames, names);
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) Application(alien4cloud.model.application.Application) Test(org.junit.Test)

Example 3 with Application

use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.

the class EsDaoCrudTest method saveApplications.

private void saveApplications() {
    Application app = new Application();
    app.setId("1");
    app.setName("app1");
    app.setDescription("this is app1");
    dao.save(app);
    app.setId("2");
    app.setName("app2");
    app.setDescription("this is app2");
    dao.save(app);
    app.setId("3");
    app.setName("app3");
    app.setDescription("this is app3");
    dao.save(app);
    refresh();
}
Also used : Application(alien4cloud.model.application.Application)

Example 4 with Application

use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.

the class ArchiveExportService method getYaml.

/**
 * Get the yaml string out of a cloud service archive and topology.
 *
 * @param csar             The csar that contains archive meta-data.
 * @param topology         The topology template within the archive.
 * @param generateWorkflow check if we generate the workflow
 * @param dslVersion       the TOSCA DSL version to use
 * @param velocityCtx      allows to provide some extra configuration options to velocity
 *
 * @return The TOSCA yaml file that describe the topology.
 */
public String getYaml(Csar csar, Topology topology, boolean generateWorkflow, String dslVersion, Map<String, Object> velocityCtx) {
    if (velocityCtx == null) {
        velocityCtx = new HashMap<>();
    }
    velocityCtx.put("topology", topology);
    velocityCtx.put("template_name", csar.getName());
    velocityCtx.put("template_version", csar.getVersion());
    velocityCtx.put("hasCustomWorkflows", hasCustomWorkflows(topology));
    velocityCtx.put("generateWorkflow", generateWorkflow);
    if (csar.getDescription() == null) {
        velocityCtx.put("template_description", "");
    } else {
        velocityCtx.put("template_description", csar.getDescription());
    }
    User loggedUser = AuthorizationUtil.getCurrentUser();
    String author = csar.getTemplateAuthor();
    if (author == null) {
        author = loggedUser != null ? loggedUser.getUsername() : null;
    }
    velocityCtx.put("template_author", author);
    velocityCtx.put("topology_description", topology.getDescription());
    if (topology.getDescription() == null && ArchiveDelegateType.APPLICATION.toString().equals(csar.getDelegateType())) {
        // if the archive has no description let's use the one of the application
        Application application = applicationService.getOrFail(csar.getDelegateId());
        velocityCtx.put("topology_description", application.getDescription());
    }
    try {
        StringWriter writer = new StringWriter();
        VelocityUtil.generate("org/alien4cloud/tosca/exporter/topology-" + dslVersion + ".yml.vm", writer, velocityCtx);
        return writer.toString();
    } catch (Exception e) {
        log.error("Exception while templating YAML for topology " + topology.getId(), e);
        return ExceptionUtils.getFullStackTrace(e);
    }
}
Also used : User(alien4cloud.security.model.User) StringWriter(java.io.StringWriter) Application(alien4cloud.model.application.Application)

Example 5 with Application

use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.

the class AlienContextVariables method getProperty.

@Override
public Object getProperty(String name) {
    if (!name.startsWith("a4c.")) {
        return null;
    }
    switch(name) {
        case "a4c.application":
            return application;
        case "a4c.application.id":
            return ifNotNull(application, Application::getId);
        case "a4c.application.name":
            return ifNotNull(application, Application::getName);
        case "a4c.environment.type":
            return ifNotNull(applicationEnvironment, ApplicationEnvironment::getEnvironmentType);
        case "a4c.environment.name":
            return ifNotNull(applicationEnvironment, ApplicationEnvironment::getName);
    }
    // lookup for a tag
    if (name.startsWith("a4c.application.tags.")) {
        if (application != null && application.getTags() != null) {
            String tagName = StringUtils.removeStart(name, "a4c.application.tags.");
            for (Tag tag : application.getTags()) {
                if (tag.getName().equals(tagName)) {
                    return tag.getValue();
                }
            }
        }
    }
    // lookup for meta properties
    String metaName = StringUtils.removeStart(name, "a4c.");
    String metaValue = findMetaProperties(metaName, application);
    if (metaValue != null) {
        return metaValue;
    }
    metaValue = findMetaProperties(metaName, location);
    if (metaValue != null) {
        return metaValue;
    }
    return null;
}
Also used : Tag(alien4cloud.model.common.Tag) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment)

Aggregations

Application (alien4cloud.model.application.Application)103 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)45 ApiOperation (io.swagger.annotations.ApiOperation)43 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)39 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)38 Audit (alien4cloud.audit.annotation.Audit)28 List (java.util.List)14 Topology (org.alien4cloud.tosca.model.templates.Topology)14 Set (java.util.Set)12 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)11 RestResponse (alien4cloud.rest.model.RestResponse)11 Collectors (java.util.stream.Collectors)11 Map (java.util.Map)10 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)9 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)9 Arrays (java.util.Arrays)9 When (cucumber.api.java.en.When)8 Deployment (alien4cloud.model.deployment.Deployment)7 RestResponseBuilder (alien4cloud.rest.model.RestResponseBuilder)7 ApplicationEnvironmentAuthorizationDTO (alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationDTO)7