These are chat archives for cloudsoft/brooklyn-tosca

Nov 2015
Martin Harris
Nov 17 2015 16:51

Hi Folks,

We've been looking into how to translate Brooklyn Entities to TOSCA types which will enable us to build up relationships in the Alien GUI

Initially we tried the approach of adding TOSCA-specific annotations to the Brooklyn classes. This was met with some resistance as it would require us to bake TOSCA metadata into Brooklyn entities

I'd like to suggest the following, which should hopefully be more appealing to both camps (no pun intended)

Firstly, we would create a ToscaMetadataProvider interface, which would live in the brooklyn-tosca codebase (preferably in a sub-project to make it a lighter-weight dependency on downstream projects - see below). The interface would look something like this:

public interface ToscaMetadataProvider {
    Optional<String> getToscaType(String externalType, Collection<String> interfaces);
    Optional<Map<?,?>> getSomeOtherMetadata(String externalType, Collection<String> interfaces);

Here getSomeOtherMetadata is just a placeholder for other methods for getting requirements, capabilities etc

The getToscaType method receives a collection of all interfaces implemented by the type (which would be retrieved from Brooklyn's REST API). This would allow the implementation to choose a TOSCA type based on an interface such as HasDatastoreUrl rather than having to be aware of MySqlNode, PostgreSqlNode, and the as-yet unwritten FooSqlNode

A very basic sample implementation would be as follows:

public class BrooklynToscaMetadataProvider implements ToscaMetadataProvider {

    private static final Map<String, String> EXTERNAL_TYPE_TO_TOSCA_TYPE = ImmutableMap.of(
            "org.apache.brooklyn.entity.database.mysql.MySqlNode", "brooklyn.tosca.types.mysql"    

    private static final Map<String, String> INTERFACE_TO_TOSCA_TYPE = ImmutableMap.of(
            "org.apache.brooklyn.entity.database.HasDatastoreUrl", "brooklyn.tosca.types.database",
            "", "brooklyn.tosca.types.compute"

    public Optional<String> getToscaType(String externalType, Collection<String> interfaces) {
        if (EXTERNAL_TYPE_TO_TOSCA_TYPE.containsKey(externalType)) {
            return Optional.of(EXTERNAL_TYPE_TO_TOSCA_TYPE.get(externalType));
        for (String interfaz : INTERFACE_TO_TOSCA_TYPE.keySet()) {
            if (interfaces.contains(interfaz)) {
                return Optional.of(INTERFACE_TO_TOSCA_TYPE.get(interfaz));
        return Optional.absent();

    public Optional<Map<?, ?>> getSomeOtherMetadata(String externalType, Collection<String> interfaces) {
        return Optional.absent();

The next step would be to make this class available to the A4C Brooklyn plugin. For this, I propose (if possible) adding it as confiuration to conf/alien4cloud-config.yml, e.g. as follows:

- alien4cloud.brooklyn.BrooklynToscaMetadataProvider

By making it a list, this will allow downstream project to provide their own ToscaMetadataProvider implementations which could override the Brooklyn implementation, in addition to providing Metadata for their own custom Brooklyn blueprints

Hope this makes sense, and any feedback would be welcome