You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2015/07/24 08:07:04 UTC

[jira] [Commented] (BROOKLYN-143) Add support for Hazelcast

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

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

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

    https://github.com/apache/incubator-brooklyn/pull/642#discussion_r35397530
  
    --- Diff: sandbox/nosql/src/main/java/brooklyn/entity/nosql/hazelcast/HazelcastNodeSshDriver.java ---
    @@ -0,0 +1,159 @@
    +/*
    + * 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.nosql.hazelcast;
    +
    +import static java.lang.String.format;
    +
    +import java.util.List;
    +import java.util.concurrent.ExecutionException;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import brooklyn.entity.Entity;
    +import brooklyn.entity.basic.Entities;
    +import brooklyn.entity.basic.EntityLocal;
    +import brooklyn.entity.java.JavaSoftwareProcessSshDriver;
    +import brooklyn.location.basic.SshMachineLocation;
    +import brooklyn.util.collections.MutableMap;
    +import brooklyn.util.os.Os;
    +import brooklyn.util.ssh.BashCommands;
    +
    +import com.google.common.collect.ImmutableList;
    +import com.google.common.collect.Lists;
    +
    +public class HazelcastNodeSshDriver extends JavaSoftwareProcessSshDriver implements HazelcastNodeDriver {
    +    
    +    private static final Logger LOG = LoggerFactory.getLogger(HazelcastNodeSshDriver.class);
    +
    +    public HazelcastNodeSshDriver(EntityLocal entity, SshMachineLocation machine) {
    +        super(entity, machine);
    +    }
    +
    +    @Override
    +    public void preInstall() {
    +        resolver = Entities.newDownloader(this);
    +    }
    +
    +    @Override
    +    public void install() {
    +        List<String> urls = resolver.getTargets();
    +        String saveAs = resolver.getFilename();
    +        
    +        List<String> commands = ImmutableList.<String>builder()
    +            .add(BashCommands.installJavaLatestOrWarn())
    +            .addAll(BashCommands.commandsToDownloadUrlsAs(urls, saveAs))
    +            .build();
    +        
    +        newScript(INSTALLING).body.append(commands).execute();
    +    }
    +
    +    @Override
    +    public void customize() {
    +        if (LOG.isInfoEnabled()) {
    +            LOG.info("Customizing {}", entity.getAttribute(HazelcastNode.NODE_NAME));
    +        }
    +        
    +        ImmutableList.Builder<String> commands = new ImmutableList.Builder<String>()
    +                .add("mkdir -p lib conf log")
    +                .add(String.format("cp %s/%s %s/lib/", getInstallDir(), resolver.getFilename(), getRunDir()));
    +
    +        newScript(CUSTOMIZING)
    +                .body.append(commands.build())
    +                .failOnNonZeroResultCode()
    +                .execute();
    +        
    +        copyTemplate(entity.getConfig(HazelcastNode.CONFIG_TEMPLATE_URL), Os.mergePathsUnix(getRunDir(), "conf", getConfigFileName()));
    +        
    +    }
    +
    +    @Override
    +    public void launch() {
    +        
    +        entity.setAttribute(HazelcastNode.PID_FILE, Os.mergePathsUnix(getRunDir(), PID_FILENAME));
    +        
    +        String maxHeapMemorySize = getHeapMemorySize();
    +        
    +        if (LOG.isInfoEnabled()) {
    +            LOG.info("Launching {} with heap memory of {}", entity, maxHeapMemorySize);
    +        }
    +        
    +        // Setting initial heap size (Xms) size to match max heap size (Xms) at first
    +        String initialHeapMemorySize = maxHeapMemorySize;
    +        
    +        StringBuilder commandBuilder = new StringBuilder()
    +            .append(format("nohup java -cp ./lib/%s", resolver.getFilename()))
    +            .append(format(" -Xmx%s -Xms%s", maxHeapMemorySize, initialHeapMemorySize))
    +            .append(format(" -Dhazelcast.config=./conf/%s", getConfigFileName()))
    +            .append(format(" com.hazelcast.core.server.StartServer >> %s 2>&1 </dev/null &", getLogFileLocation()));
    +        
    +        newScript(MutableMap.of(USE_PID_FILE, true), LAUNCHING)
    +            .updateTaskAndFailOnNonZeroResultCode()
    +            .body.append(commandBuilder.toString())
    +            .execute();
    +    }
    +       
    +    public String getConfigFileName() {
    +        return entity.getConfig(HazelcastNode.CONFIG_FILE_NAME);
    +    }
    +    
    +    public String getHeapMemorySize() {
    +        return entity.getConfig(HazelcastNode.NODE_HEAP_MEMORY_SIZE);
    +    }
    +    
    +    @Override
    +    public boolean isRunning() {       
    +        return newScript(MutableMap.of(USE_PID_FILE, true), CHECK_RUNNING).execute() == 0;
    +    }
    +    
    +    @Override
    +    public void stop() {
    +        newScript(MutableMap.of(USE_PID_FILE, true), STOPPING).execute();
    +    }
    +    
    +    @Override
    +    public void kill() {
    +        newScript(MutableMap.of(USE_PID_FILE, true), KILLING).execute();
    +    }
    +
    +    public List<String> getHazelcastNodesList() throws ExecutionException, InterruptedException {
    +        HazelcastCluster cluster = (HazelcastCluster) entity.getParent();
    +        List<String> result = Lists.newArrayList();
    +
    +        for (Entity member : cluster.getMembers()) {
    +            String address = Entities.attributeSupplierWhenReady(member, HazelcastNode.SUBNET_ADDRESS).get();
    +            Integer port = Entities.attributeSupplierWhenReady(member, HazelcastNode.NODE_PORT).get();
    +            
    +            String addressAndPort = String.format("%s:%d", address, port);
    +            
    +            if (LOG.isInfoEnabled()) {
    +                LOG.info("Adding {} to the members' list of {}", addressAndPort, entity.getAttribute(HazelcastNode.NODE_NAME));
    +            }
    +            result.add(addressAndPort);
    +        }
    +        
    +        return result;
    +    }
    +
    +    @Override
    +    protected String getLogFileLocation() {
    +        return Os.mergePathsUnix(getRunDir(),"/log/out.log");
    --- End diff --
    
    Personal preference for `console` or `console.log`; the name `out.log` makes it feel like it might be just stdout, but it also has stderr. No strong feelings though.


> Add support for Hazelcast
> -------------------------
>
>                 Key: BROOKLYN-143
>                 URL: https://issues.apache.org/jira/browse/BROOKLYN-143
>             Project: Brooklyn
>          Issue Type: New Feature
>            Reporter: Yavor Yanchev
>            Priority: Minor
>
> Hazelcast is a clustering and highly scalable data distribution platform for Java.
> Some of the features it provides
> Distributed java.util.{Queue, Set, List, Map}
> Distributed java.util.concurrency.locks.Lock
> Distributed java.util.concurrent.ExecutorService
> Distributed Indexing and Query support



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)