brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjcorb...@apache.org
Subject [1/8] incubator-brooklyn git commit: Nodejs riak sample app
Date Mon, 11 May 2015 13:32:54 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master addf30e23 -> 125f01e00


Nodejs riak sample app

- Refactoring the NodeJsWebAppSshDriver
install packages from package.json as non-root


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/ac3bab73
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/ac3bab73
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/ac3bab73

Branch: refs/heads/master
Commit: ac3bab73dc271a6c9e5e2f769e9c1d5e2f053b85
Parents: 7b97cee
Author: Valentin Aitken <valentin.aitken@cloudsoftcorp.com>
Authored: Wed Apr 22 20:56:49 2015 +0300
Committer: Valentin Aitken <valentin.aitken@cloudsoftcorp.com>
Committed: Sun Apr 26 20:27:57 2015 +0300

----------------------------------------------------------------------
 .../brooklyn/demo/nodejs-riak-todo.yaml         | 46 ++++++++++++++++++++
 .../brooklyn/entity/nosql/riak/RiakCluster.java |  2 +
 .../entity/nosql/riak/RiakClusterImpl.java      |  3 ++
 .../webapp/nodejs/NodeJsWebAppSshDriver.java    | 13 +++---
 4 files changed, 59 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac3bab73/examples/simple-web-cluster/src/main/resources/brooklyn/demo/nodejs-riak-todo.yaml
----------------------------------------------------------------------
diff --git a/examples/simple-web-cluster/src/main/resources/brooklyn/demo/nodejs-riak-todo.yaml
b/examples/simple-web-cluster/src/main/resources/brooklyn/demo/nodejs-riak-todo.yaml
new file mode 100644
index 0000000..d963671
--- /dev/null
+++ b/examples/simple-web-cluster/src/main/resources/brooklyn/demo/nodejs-riak-todo.yaml
@@ -0,0 +1,46 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+name: "Node.JS Todo Application"
+origin: "https://github.com/amirrajan/nodejs-todo/"
+location:
+  jclouds:aws-ec2:us-west-1:
+    imageId: us-west-1/ami-c33cdd87
+services:
+- type: brooklyn.entity.nosql.riak.RiakCluster
+  initialSize: 2
+  id: mycluster
+  brooklyn.config:
+    provisioning.properties:
+      osFamily: centos
+      minCores: 4
+      minRam: 2048
+- type: brooklyn.entity.webapp.nodejs.NodeJsWebAppService
+  id: nodejs-riak1
+  name: "Node.JS"
+  brooklyn.config:
+    gitRepoUrl:
+      "https://github.com/bostko/nodejs-todo.git"
+    appFileName: server.js
+    appName: nodejs-todo
+    nodePackages:
+    - basho-riak-client
+    env:
+      NODE_ENV: production
+      RIAK_NODES: >
+        $brooklyn:component("mycluster").attributeWhenReady("riak.cluster.nodeListPbPort")
+    launch.latch: $brooklyn:component("mycluster").attributeWhenReady("service.isUp")
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac3bab73/software/nosql/src/main/java/brooklyn/entity/nosql/riak/RiakCluster.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/riak/RiakCluster.java b/software/nosql/src/main/java/brooklyn/entity/nosql/riak/RiakCluster.java
index a5a3838..41aa6be 100644
--- a/software/nosql/src/main/java/brooklyn/entity/nosql/riak/RiakCluster.java
+++ b/software/nosql/src/main/java/brooklyn/entity/nosql/riak/RiakCluster.java
@@ -54,6 +54,8 @@ public interface RiakCluster extends DynamicCluster {
 
     AttributeSensor<String> NODE_LIST = Sensors.newStringSensor("riak.cluster.nodeList",
"List of nodes (including ports), comma separated");
 
+    AttributeSensor<String> NODE_LIST_PB_PORT = Sensors.newStringSensor("riak.cluster.nodeListPbPort",
"List of nodes (including ports for riak db clients), comma separated");
+
     AttributeSensor<URI> RIAK_CONSOLE_URI = Attributes.MAIN_URI;
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac3bab73/software/nosql/src/main/java/brooklyn/entity/nosql/riak/RiakClusterImpl.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/riak/RiakClusterImpl.java
b/software/nosql/src/main/java/brooklyn/entity/nosql/riak/RiakClusterImpl.java
index becaee7..637346e 100644
--- a/software/nosql/src/main/java/brooklyn/entity/nosql/riak/RiakClusterImpl.java
+++ b/software/nosql/src/main/java/brooklyn/entity/nosql/riak/RiakClusterImpl.java
@@ -182,13 +182,16 @@ public class RiakClusterImpl extends DynamicClusterImpl implements RiakCluster
{
 
     private void calculateClusterAddresses() {
         List<String> addresses = Lists.newArrayList();
+        List<String> addressesPbPort = Lists.newArrayList();
         for (Entity entity : this.getMembers()) {
             if (entity instanceof RiakNode && entity.getAttribute(Attributes.SERVICE_UP))
{
                 RiakNode riakNode = (RiakNode) entity;
                 addresses.add(riakNode.getAttribute(Attributes.SUBNET_HOSTNAME) + ":" + riakNode.getAttribute(RiakNode.RIAK_WEB_PORT));
+                addressesPbPort.add(riakNode.getAttribute(Attributes.SUBNET_HOSTNAME) + ":"
+ riakNode.getAttribute(RiakNode.RIAK_PB_PORT));
             }
         }
         setAttribute(RiakCluster.NODE_LIST, Joiner.on(",").join(addresses));
+        setAttribute(RiakCluster.NODE_LIST_PB_PORT, Joiner.on(",").join(addressesPbPort));
     }
 
     protected boolean belongsInServerPool(Entity member) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac3bab73/software/webapp/src/main/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppSshDriver.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/main/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppSshDriver.java
b/software/webapp/src/main/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppSshDriver.java
index fb2eb25..3beee70 100644
--- a/software/webapp/src/main/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppSshDriver.java
+++ b/software/webapp/src/main/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppSshDriver.java
@@ -103,6 +103,7 @@ public class NodeJsWebAppSshDriver extends AbstractSoftwareProcessSshDriver
impl
                         BashCommands.installPackage("software-properties-common python-software-properties
python g++ make"),
                         BashCommands.sudo("add-apt-repository ppa:chris-lea/node.js"))))
                 .add(BashCommands.installPackage(MutableMap.of("yum", "git nodejs npm", "apt",
"git-core nodejs"), null))
+                .add("mkdir \"$HOME/.npm\"")
                 .add(BashCommands.sudo("npm install -g n"))
                 .add(BashCommands.sudo("n " + getEntity().getConfig(SoftwareProcess.SUGGESTED_VERSION)))
                 .build();
@@ -116,11 +117,6 @@ public class NodeJsWebAppSshDriver extends AbstractSoftwareProcessSshDriver
impl
     public void customize() {
         List<String> commands = Lists.newLinkedList();
 
-        List<String> packages = getEntity().getConfig(NodeJsWebAppService.NODE_PACKAGE_LIST);
-        if (packages != null && packages.size() > 0) {
-            commands.add(BashCommands.sudo("npm install -g " + Joiner.on(' ').join(packages)));
-        }
-
         String gitRepoUrl = getEntity().getConfig(NodeJsWebAppService.APP_GIT_REPOSITORY_URL);
         String archiveUrl = getEntity().getConfig(NodeJsWebAppService.APP_ARCHIVE_URL);
         String appName = getEntity().getConfig(NodeJsWebAppService.APP_NAME);
@@ -128,12 +124,19 @@ public class NodeJsWebAppSshDriver extends AbstractSoftwareProcessSshDriver
impl
             throw new IllegalStateException("Only one of Git or archive URL must be set for
" + getEntity());
         } else if (Strings.isNonBlank(gitRepoUrl)) {
             commands.add(String.format("git clone %s %s", gitRepoUrl, appName));
+            commands.add(String.format("cd %s", appName));
         } else if (Strings.isNonBlank(archiveUrl)) {
             ArchiveUtils.deploy(archiveUrl, getMachine(), getRunDir());
         } else {
             throw new IllegalStateException("At least one of Git or archive URL must be set
for " + getEntity());
         }
 
+        commands.add(BashCommands.ifFileExistsElse1("package.json", "npm install"));
+        List<String> packages = getEntity().getConfig(NodeJsWebAppService.NODE_PACKAGE_LIST);
+        if (packages != null && packages.size() > 0) {
+            commands.add(BashCommands.sudo("npm install -g " + Joiner.on(' ').join(packages)));
+        }
+
         newScript(CUSTOMIZING)
                 .body.append(commands)
                 .execute();


Mime
View raw message