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));
}
}
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);
}
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();
}
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);
}
}
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;
}
Aggregations