use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class PolicyTemplatePostProcessor method process.
@Override
public void process(final PolicyTemplate instance) {
// ensure type exists
referencePostProcessor.process(new ReferencePostProcessor.TypeReference(instance, instance.getType(), PolicyType.class));
final PolicyType policyType = ToscaContext.get(PolicyType.class, instance.getType());
if (policyType == null) {
// error managed by the reference post processor.
return;
}
final Topology topology = ((ArchiveRoot) ParsingContextExecution.getRoot().getWrappedInstance()).getTopology();
// check that the targets are exiting node templates
// TODO should we also check the type of the target, see if it matches with one provided in PolicyType.getTargets() ?
safe(instance.getTargets()).forEach(target -> {
if (!safe((topology.getNodeTemplates())).containsKey(target)) {
// Dispatch an error.
Node node = ParsingContextExecution.getObjectToNodeMap().get(instance.getTargets());
ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.POLICY_TARGET_NOT_FOUND, instance.getName(), node.getStartMark(), null, node.getEndMark(), target));
}
});
// Merge the policy template with data coming from the type (default values etc.).
PolicyTemplate tempObject = TemplateBuilder.buildPolicyTemplate(policyType, instance, false);
instance.setProperties(tempObject.getProperties());
propertyValueChecker.checkProperties(policyType, instance.getProperties(), instance.getName());
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class EditionContextManager method setup.
@PostConstruct
public void setup() {
// initialize the cache
contextCache = CacheBuilder.newBuilder().expireAfterAccess(30, TimeUnit.MINUTES).removalListener(new RemovalListener<String, EditionContext>() {
@Override
public void onRemoval(RemovalNotification<String, EditionContext> removalNotification) {
log.debug("Topology edition context with id {} has been evicted. {} pending operations are lost.", removalNotification.getKey(), removalNotification.getValue().getOperations().size());
for (AbstractEditorOperation operation : removalNotification.getValue().getOperations()) {
if (operation instanceof UpdateFileOperation) {
String fileId = ((UpdateFileOperation) operation).getTempFileId();
if (artifactRepository.isFileExist(fileId)) {
artifactRepository.deleteFile(fileId);
}
}
}
}
}).build(new CacheLoader<String, EditionContext>() {
@Override
public EditionContext load(String csarId) throws Exception {
log.debug("Loading edition context for archive {}", csarId);
Csar csar = csarService.getOrFail(csarId);
Topology topology = topologyServiceCore.getOrFail(csarId);
// check if the topology git repository has been created already
Path topologyGitPath = repositoryService.createGitDirectory(csar);
log.debug("Edition context for archive {} loaded", csar);
return new EditionContext(csar, topology, topologyGitPath);
}
});
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class EditionContextManager method reset.
/**
* Reset the state of the topology context to it's initial state.
*
* @throws IOException In case the parsing of the directory content fails.
*/
public void reset() throws IOException {
Topology topology = topologyServiceCore.getOrFail(getTopology().getId());
contextThreadLocal.get().reset(topology);
ToscaContext.set(contextThreadLocal.get().getToscaContext());
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class TopologyCatalogService method createTopologyAsTemplate.
@Override
public Topology createTopologyAsTemplate(String name, String description, String version, String workspace, String fromTopologyId) {
NameValidationUtils.validate("topologyTemplateName", name);
// Every version of a topology template has a Cloud Service Archive
Csar csar = new Csar(name, StringUtils.isNotBlank(version) ? version : VersionUtil.DEFAULT_VERSION_NAME);
csar.setWorkspace(workspace);
csar.setDelegateType(ArchiveDelegateType.CATALOG.toString());
csar.setToscaDefinitionsVersion(ToscaParser.LATEST_DSL);
if (description == null) {
csar.setDescription("This archive has been created with alien4cloud.");
} else {
csar.setDescription("Enclosing archive for topology " + description);
}
Topology topology;
if (fromTopologyId != null) {
// "cloning" the topology
topology = alienDAO.findById(Topology.class, fromTopologyId);
} else {
topology = new Topology();
}
topology.setDescription(description);
topology.setArchiveName(csar.getName());
topology.setArchiveVersion(csar.getVersion());
topology.setWorkspace(csar.getWorkspace());
archiveIndexer.importNewArchive(csar, topology, null);
return topology;
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class EditorService method checkTopologyRecovery.
/**
* Checks if the topology needs to be recovered and eventually throws an error.
* The {@link RecoverTopologyOperation} is cache for later use in recovering process
*/
public void checkTopologyRecovery() {
Topology topology = EditionContextManager.getTopology();
EditionContext context = EditionContextManager.get();
context.setRecoveryOperation(recoveryHelperService.buildRecoveryOperation(topology));
if (context.getRecoveryOperation() != null) {
throw new RecoverTopologyException("The topology needs to be recovered.", context.getRecoveryOperation());
}
}
Aggregations