brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (BROOKLYN-12) Add Node.JS application support
Date Tue, 05 Aug 2014 13:19:13 GMT

    [ https://issues.apache.org/jira/browse/BROOKLYN-12?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14086247#comment-14086247
] 

ASF GitHub Bot commented on BROOKLYN-12:
----------------------------------------

Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/94#discussion_r15810605
  
    --- Diff: software/webapp/src/main/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppSshDriver.java
---
    @@ -0,0 +1,161 @@
    +/*
    + * 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.
    + */
    +package brooklyn.entity.webapp.nodejs;
    +
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Set;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import brooklyn.entity.basic.AbstractSoftwareProcessSshDriver;
    +import brooklyn.entity.basic.Attributes;
    +import brooklyn.entity.basic.SoftwareProcess;
    +import brooklyn.entity.webapp.WebAppService;
    +import brooklyn.location.basic.SshMachineLocation;
    +import brooklyn.util.collections.MutableList;
    +import brooklyn.util.collections.MutableMap;
    +import brooklyn.util.file.ArchiveUtils;
    +import brooklyn.util.os.Os;
    +import brooklyn.util.ssh.BashCommands;
    +import brooklyn.util.text.Strings;
    +
    +import com.google.common.base.Joiner;
    +import com.google.common.collect.ImmutableMap;
    +import com.google.common.collect.ImmutableSet;
    +import com.google.common.collect.Iterables;
    +import com.google.common.collect.Lists;
    +
    +public class NodeJsWebAppSshDriver extends AbstractSoftwareProcessSshDriver implements
NodeJsWebAppDriver {
    +
    +    private static final Logger LOG = LoggerFactory.getLogger(NodeJsWebAppService.class);
    +
    +    public NodeJsWebAppSshDriver(NodeJsWebAppServiceImpl entity, SshMachineLocation machine)
{
    +        super(entity, machine);
    +    }
    +
    +    public NodeJsWebAppServiceImpl getEntity() {
    +        return (NodeJsWebAppServiceImpl) super.getEntity();
    +    }
    +
    +    @Override
    +    public Integer getHttpPort() {
    +        return getEntity().getAttribute(Attributes.HTTP_PORT);
    +    }
    +
    +    @Override
    +    public void postLaunch() {
    +        String rootUrl = String.format("http://%s:%d/", getHostname(), getHttpPort());
    +        entity.setAttribute(WebAppService.ROOT_URL, rootUrl);
    +    }
    +
    +    protected Map<String, Integer> getPortMap() {
    +        return ImmutableMap.of("http", getEntity().getAttribute(WebAppService.HTTP_PORT));
    +    }
    +
    +    @Override
    +    public Set<Integer> getPortsUsed() {
    +        return ImmutableSet.<Integer>builder()
    +                .addAll(super.getPortsUsed())
    +                .addAll(getPortMap().values())
    +                .build();
    +    }
    +
    +    @Override
    +    public void install() {
    +        List<String> packages = getEntity().getConfig(NodeJsWebAppService.NODE_PACKAGE_LIST);
    +        LOG.info("Installing Node.JS {} {}", getEntity().getConfig(SoftwareProcess.SUGGESTED_VERSION),
Iterables.toString(packages));
    +
    +        List<String> commands = MutableList.<String>builder()
    +                .add(BashCommands.INSTALL_CURL)
    +                .add(BashCommands.ifExecutableElse0("apt-get", BashCommands.chain(
    +                        BashCommands.installPackage("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(BashCommands.sudo("npm install -g n"))
    +                .add(BashCommands.sudo("n " + getEntity().getConfig(SoftwareProcess.SUGGESTED_VERSION)))
    +                .build();
    +
    +        if (packages != null && packages.size() > 0) {
    +            commands.add(BashCommands.sudo("npm install -g " + Joiner.on(' ').join(packages)));
    +        }
    +
    +        newScript(INSTALLING)
    +                .body.append(commands)
    +                .execute();
    +    }
    +
    +    @Override
    +    public void customize() {
    +        List<String> commands = Lists.newLinkedList();
    +
    +        String gitRepoUrl = getEntity().getConfig(NodeJsWebAppService.APP_GIT_REPOSITORY_URL);
    +        String archiveUrl = getEntity().getConfig(NodeJsWebAppService.APP_ARCHIVE_URL);
    +        String appName = getEntity().getConfig(NodeJsWebAppService.APP_NAME);
    +
    +        if (Strings.isNonBlank(gitRepoUrl) && Strings.isNonBlank(archiveUrl))
{
    +            throw new IllegalStateException("Only one of Git or archive URL must be set");
    +        } else if (Strings.isNonBlank(gitRepoUrl)) {
    +            commands.add(String.format("git clone %s %s", gitRepoUrl, 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");
    +        }
    +
    +        newScript(CUSTOMIZING)
    +                .body.append(commands)
    +                .execute();
    +    }
    +
    +    @Override
    +    public void launch() {
    +        List<String> commands = Lists.newLinkedList();
    +
    +        String appName = getEntity().getConfig(NodeJsWebAppService.APP_NAME);
    --- End diff --
    
    I've added (in too many places!):
    
        protected <K> K getRequiredConfig(ConfigKey<K> key) {
            return checkNotNull(getConfig(key), key.getName());
        }
    
    I presume this will fail in a strange way if any of those are null (i.e. command to exec
will contain the string `"null"`).


> Add Node.JS application support
> -------------------------------
>
>                 Key: BROOKLYN-12
>                 URL: https://issues.apache.org/jira/browse/BROOKLYN-12
>             Project: Brooklyn
>          Issue Type: New Feature
>         Environment: Linux
>            Reporter: Andrew Kennedy
>            Assignee: Andrew Kennedy
>
> Create entities and blueprints to deploy and manage Node.JS applications and clustered
services.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message