Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BROOKLYN-177] wip: drag and drop support for yaml editor #930

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

azbarcea
Copy link
Member

@azbarcea azbarcea commented Oct 1, 2015

No description provided.

@azbarcea
Copy link
Member Author

azbarcea commented Oct 1, 2015

  • drag
    brooklyn-drag-01
  • drop
    brooklyn-drag-02
  • the code editor view is now persistent
    brooklyn-drag-03

The following known issues:

  • the drop event will paste the JSON format and not the YAML. The current text is:

is:

services: [{ type: org.apache.brooklyn.entity.brooklynnode.BrooklynEntityMirror }]

should be:

- type: org.apache.brooklyn.entity.brooklynnode.BrooklynEntityMirror

or even:

services:
- type: org.apache.brooklyn.entity.brooklynnode.BrooklynEntityMirror

To make the drop event context dependent (exists or not the services:), then, a javascript yaml (blueprint) parser should be created (like [1]). It should understand CAMP syntax.

References:
[1] - http://www.json2yaml.com/

@neykov
Copy link
Member

neykov commented Oct 2, 2015

btw Brooklyn already has a YAML parser included - https://github.com/nodeca/js-yaml, see

@azbarcea
Copy link
Member Author

azbarcea commented Oct 2, 2015

What I meant, is a Brooklyn Blueprint parser, based on js-yaml. The context belongs to CAMP semantics.

What is your thought?

@neykov
Copy link
Member

neykov commented Oct 2, 2015

It's in the context of your reference to http://www.json2yaml.com/, js-yaml can do the conversion from json to yaml.

@grkvlt
Copy link
Member

grkvlt commented Oct 2, 2015

@neykov what @azbarcea means is we want to take the YAML syntactical parsing (via the existing Brooklyn capabilities) and extend it with the semantic meaning of the CAMP (and eventially TOSCA or Docker Compose etc.) format.

@grkvlt
Copy link
Member

grkvlt commented Oct 2, 2015

@morganbrooke can you take a look at this, please?

@azbarcea
Copy link
Member Author

azbarcea commented Oct 2, 2015

some more example how it should happen when you do drop ...

# Please add your blueprint here
services: 
- type: org.apache.brooklyn.entity.database.mariadb.MariaDbNode
#  broklyn.config:
#  - activemq.brokerName: localhost
#    activemq.install.mirror.url: http://www.mirrorservice.org/sites/ftp.apache.org/activemq
#    activemq.jetty.port: 8161
#    activemq.templateConfigurationUrl: config/activemq.xml

or even:

# Please add your blueprint here
services: 
- type: org.apache.brooklyn.entity.database.mariadb.MariaDbNode
  broklyn.config:
  - activemq.brokerName: localhost
    activemq.install.mirror.url: http://www.mirrorservice.org/sites/ftp.apache.org/activemq
    activemq.jetty.port: 8161
    activemq.templateConfigurationUrl: config/activemq.xml

The rest API returns the weird text in the planYaml field, which is not JSON, neither yaml ... Also the above text that is inserted, we should either get it from the REST API, or I could guess how to generate it.

Any of your thoughts?

@morganbrooke
Copy link
Contributor

So if I'm understanding this correctly, I think you just need to use JSON.parse method and then stringify the YAML in the JavaScript.

@morganbrooke
Copy link
Contributor

npm install json2yaml is a package manager that allows this fairly easily it looks like:
http://jsontoyaml.com
So maybe look into that to resolve the issue?

@azbarcea
Copy link
Member Author

azbarcea commented Oct 2, 2015

Please take a look at the String you want to parse, stringify. It needs to be a valid JSON first.

Either we modify the REST or we fix it in javascript. Any ideas?

@morganbrooke
Copy link
Contributor

I see what you're saying, let me check out a few options.

@neykov
Copy link
Member

neykov commented Oct 5, 2015

  • The text which comes from the REST API is valid YAML, not JSON (JSON is a subset of YAML). You can do
var bp = jsyaml.load("services: [{ type: org.apache.brooklyn.entity.brooklynnode.BrooklynEntityMirror }]");
jsyaml.dump(bp);

which will spit out:

services:
- type: org.apache.brooklyn.entity.brooklynnode.BrooklynEntityMirror

Both of them are YAML, the latter one being idiomatic. But the yamlPlan is not useful in this case because:

  • The yamlPlan of catalog items is the plan used to create the item, not example usage. Try dropping 1-server-template:0.9.0-SNAPSHOT from the default catalog for example to see what I mean. What should be dropped instead is how the item is to be used, which is just the symbolicName:version pair.
    Having the config keys as part of the pasted data is a good idea, but this is not available from the REST API. It can still be obtained though, for example the catalog docs extract the information offline, using the CLI item-lister command.

@morganbrooke
Copy link
Contributor

Wow, great work @neykov!
Thanks!

@ahgittin
Copy link
Contributor

@azbarcea any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants