You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by nakomis <gi...@git.apache.org> on 2015/02/25 10:49:01 UTC

[GitHub] incubator-brooklyn pull request: Adds template processing to the M...

GitHub user nakomis opened a pull request:

    https://github.com/apache/incubator-brooklyn/pull/530

    Adds template processing to the MySQL database creation script

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/nakomis/incubator-brooklyn fix/mysql-creation-script-template

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-brooklyn/pull/530.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #530
    
----
commit 65eba643c8242beb02efebb2cf7c31576917d6e7
Author: Martin Harris <gi...@nakomis.com>
Date:   2015-02-25T09:48:32Z

    Adds template processing to the MySQL database creation script

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Adds template processing to the M...

Posted by sjcorbett <gi...@git.apache.org>.
Github user sjcorbett commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/530#discussion_r25330596
  
    --- Diff: software/database/src/main/java/brooklyn/entity/database/mysql/MySqlSshDriver.java ---
    @@ -186,9 +186,13 @@ protected void copyDatabaseConfigScript() {
         }
     
         protected boolean copyDatabaseCreationScript() {
    -        InputStream creationScript = DatastoreMixins.getDatabaseCreationScript(entity);
    -        if (creationScript==null) return false;
    -        getMachine().copyTo(creationScript, getRunDir() + "/creation-script.sql");
    +        String creationScriptContents = DatastoreMixins.getDatabaseCreationScriptAsString(entity);
    +        if (creationScriptContents==null) return false;
    +
    +        creationScriptContents = processTemplateContents(creationScriptContents);
    +        Reader creationContents = new StringReader(creationScriptContents);
    +
    +        getMachine().copyTo(creationContents, getRunDir() + "/creation-script.sql");
    --- End diff --
    
    You should just use `copyTemplate` instead of the previous four lines.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Adds template processing to the M...

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/530#discussion_r25697825
  
    --- Diff: software/database/src/main/java/brooklyn/entity/database/mysql/MySqlSshDriver.java ---
    @@ -186,9 +192,20 @@ protected void copyDatabaseConfigScript() {
         }
     
         protected boolean copyDatabaseCreationScript() {
    -        InputStream creationScript = DatastoreMixins.getDatabaseCreationScript(entity);
    -        if (creationScript==null) return false;
    -        getMachine().copyTo(creationScript, getRunDir() + "/creation-script.sql");
    +        String creationScriptContents = DatastoreMixins.getDatabaseCreationScriptAsString(entity);
    +        if (creationScriptContents==null) return false;
    +
    +        File templateFile;
    +        try {
    +            templateFile = File.createTempFile("mysql", null);
    +            templateFile.deleteOnExit();
    +            BufferedWriter writer = new BufferedWriter(new FileWriter(templateFile));
    +            writer.write (creationScriptContents);
    +        } catch (IOException e) {
    +            throw Exceptions.propagate(e);
    +        }
    +        copyTemplate(templateFile.getAbsoluteFile(), getRunDir() + "/creation-script.sql");
    +        templateFile.delete();
    --- End diff --
    
    Personally I'd have put the `copyTemplate` inside the try block, and the `templateFile.delete()` in a finally block.
    Another slight concern about this approach is that the file permission could mean the file is readable by others for the brief time it exists - if the sql script contained any passwords, that would not be good.
    
    However, I don't feel strongly enough about this to delay the PR. Happy to merge.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Adds template processing to the M...

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on the pull request:

    https://github.com/apache/incubator-brooklyn/pull/530#issuecomment-76971335
  
    Thanks @nakomis - merging.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Adds template processing to the M...

Posted by nakomis <gi...@git.apache.org>.
Github user nakomis commented on the pull request:

    https://github.com/apache/incubator-brooklyn/pull/530#issuecomment-76965859
  
    @sjcorbett PR comment addressed
    @aledsage Given that the existing integration test simply runs the Vogella, so fitting in a test for the templating could be tricky


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Adds template processing to the M...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-brooklyn/pull/530


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Adds template processing to the M...

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on the pull request:

    https://github.com/apache/incubator-brooklyn/pull/530#issuecomment-76008954
  
    Can we get an integration test, that the database creation script is being templated correctly? Or do you think that is a lot more effort than it's worth?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Adds template processing to the M...

Posted by sjcorbett <gi...@git.apache.org>.
Github user sjcorbett commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/530#discussion_r25330734
  
    --- Diff: software/database/src/main/java/brooklyn/entity/database/mysql/MySqlSshDriver.java ---
    @@ -186,9 +186,13 @@ protected void copyDatabaseConfigScript() {
         }
     
         protected boolean copyDatabaseCreationScript() {
    -        InputStream creationScript = DatastoreMixins.getDatabaseCreationScript(entity);
    -        if (creationScript==null) return false;
    -        getMachine().copyTo(creationScript, getRunDir() + "/creation-script.sql");
    +        String creationScriptContents = DatastoreMixins.getDatabaseCreationScriptAsString(entity);
    +        if (creationScriptContents==null) return false;
    +
    +        creationScriptContents = processTemplateContents(creationScriptContents);
    +        Reader creationContents = new StringReader(creationScriptContents);
    +
    +        getMachine().copyTo(creationContents, getRunDir() + "/creation-script.sql");
    --- End diff --
    
    Although `copyTemplate` wants the URI of the template so its a bit awkward with `CREATION_SCRIPT_CONTENTS`. I guess you'd have to write it out as a temporary file. I leave it up to you.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---