You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stratos.apache.org by dinithis <gi...@git.apache.org> on 2015/01/29 14:07:32 UTC

[GitHub] stratos pull request: Adding network partitions for CLI

GitHub user dinithis opened a pull request:

    https://github.com/apache/stratos/pull/198

    Adding network partitions for CLI

    Adding network partitions for CLI

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

    $ git pull https://github.com/dinithis/stratos master

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

    https://github.com/apache/stratos/pull/198.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 #198
    
----
commit f5b3927cfa48b9e6f3efe31f3ac09f31a5e82ae0
Author: Dinithi <di...@wso2.com>
Date:   2015-01-29T13:04:05Z

    Adding network partitions for CLI

----


---
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] stratos pull request: Adding network partitions for CLI

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

    https://github.com/apache/stratos/pull/198#issuecomment-72154787
  
    Adding network partitions for CLI - changed suggested modifications


---
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] stratos pull request: Adding network partitions for CLI

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

    https://github.com/apache/stratos/pull/198#issuecomment-72022527
  
    Overall this pull request looks good, however I can see considerable amount of code formattings. It would be better to do code formatting in a different pull request as it is difficult to identify your changes. I have pointed out several points to fix. Please fix them and let us know.
    Thanks


---
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] stratos pull request: Adding network partitions for CLI

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

    https://github.com/apache/stratos/pull/198#discussion_r23767029
  
    --- Diff: components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddNetworkPartitionCommand.java ---
    @@ -0,0 +1,174 @@
    +/**
    + *  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 org.apache.stratos.cli.commands;
    +
    +import org.apache.commons.cli.*;
    +import org.apache.stratos.cli.Command;
    +import org.apache.stratos.cli.RestCommandLineService;
    +import org.apache.stratos.cli.StratosCommandContext;
    +import org.apache.stratos.cli.exception.CommandException;
    +import org.apache.stratos.cli.utils.CliConstants;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.io.BufferedReader;
    +import java.io.FileReader;
    +import java.io.IOException;
    +
    +public class AddNetworkPartitionCommand implements Command<StratosCommandContext> {
    +
    +    private static final Logger logger = LoggerFactory.getLogger(AddNetworkPartitionCommand.class);
    +
    +    private final Options options;
    +
    +    public AddNetworkPartitionCommand(){
    +        options = constructOptions();
    +    }
    +
    +    private Options constructOptions() {
    +        final Options options = new Options();
    +
    +        Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
    +                "Network partition resource path");
    +        resourcePath.setArgName("resource path");
    +        options.addOption(resourcePath);
    +
    +        return options;
    +    }
    +    /**
    +     * @return The name of the command
    +     */
    +    @Override
    +    public String getName() {
    +        return "add-network-partition";
    +    }
    +
    +    /**
    +     * Information about the command
    +     *
    +     * @return The description of the command
    +     */
    +    @Override
    +    public String getDescription() {
    +        return "add network partition deployment";
    +    }
    +
    +    /**
    +     * This should return the syntax required for the command.
    +     * <p/>
    +     * Used to display help.
    +     *
    +     * @return The syntax for this command
    +     */
    +    @Override
    +    public String getArgumentSyntax() {
    +        return null;
    +    }
    +
    +    /**
    +     * The options accepted by the command
    +     *
    +     * @return The Options for the commands
    +     */
    +    @Override
    +    public Options getOptions() {
    +        return options;
    +    }
    +
    +    /**
    +     * Executing the commands. Returns a code
    +     *
    +     * @param context The context assoicated with the Command Line Application
    +     * @param args    The arguments for the command
    +     * @return The status code
    +     * @throws org.apache.stratos.cli.exception.CommandException if any errors occur when executing the command
    +     */
    +    @Override
    +    public int execute(StratosCommandContext context, String[] args) throws CommandException {
    +        if (logger.isDebugEnabled()) {
    +            logger.debug("Executing {} command...", getName());
    +            logger.info("Get name" + getName());
    --- End diff --
    
    Info log available inside the isDebugEnabled() condition.Better to change that info log.


---
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] stratos pull request: Adding network partitions for CLI

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

    https://github.com/apache/stratos/pull/198#discussion_r31002645
  
    --- Diff: components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java ---
    @@ -293,44 +297,44 @@ public void listCartridges() throws CommandException {
             }
         }
     
    -	/**
    -	 * List cartridge groups
    -	 *
    -	 * @throws CommandException
    -	 */
    -	public void listCartridgeGroups() throws CommandException {
    -		try {
    -			Type listType = new TypeToken<ArrayList<GroupBean>>() {
    -			}.getType();
    -			List<GroupBean> cartridgeGroupList = (List<GroupBean>) restClient.listEntity(ENDPOINT_LIST_CARTRIDGE_GROUPS,
    -			                                                                                listType, "Cartridge Groups");
    -
    -			if ((cartridgeGroupList == null) || (cartridgeGroupList.size() == 0)) {
    -				System.out.println("No cartridges found");
    -				return;
    -			}
    -
    -			RowMapper<GroupBean> cartridgeGroupMapper = new RowMapper<GroupBean>() {
    -				public String[] getData(GroupBean cartridgeGroup) {
    -					String[] data = new String[4];
    -					data[0] = cartridgeGroup.getName();
    -					data[1] = String.valueOf(cartridgeGroup.getCartridges().size());
    -					data[2] = String.valueOf(cartridgeGroup.getGroups().size());
    -					data[3] = String.valueOf(cartridgeGroup.isGroupScalingEnabled());
    -					return data;
    -				}
    -			};
    -
    -			GroupBean[] cartridgeGroups = new GroupBean[cartridgeGroupList.size()];
    -			cartridgeGroups = cartridgeGroupList.toArray(cartridgeGroups);
    -
    -			System.out.println("Cartridge Groups found:");
    -			CliUtils.printTable(cartridgeGroups, cartridgeGroupMapper, "Name", "No. of Cartridges", "No of Groups", "Dependency scaling");
    -		} catch (Exception e) {
    -			String message = "Error in listing cartridge groups";
    -			printError(message, e);
    -		}
    -	}
    +    /**
    +     * List cartridge groups
    +     *
    +     * @throws CommandException
    +     */
    +    public void listCartridgeGroups() throws CommandException {
    +        try {
    +            Type listType = new TypeToken<ArrayList<GroupBean>>() {
    +            }.getType();
    +            List<GroupBean> cartridgeGroupList = (List<GroupBean>) restClient.listEntity(ENDPOINT_LIST_CARTRIDGE_GROUPS,
    +                    listType, "Cartridge Groups");
    +
    +            if ((cartridgeGroupList == null) || (cartridgeGroupList.size() == 0)) {
    +                System.out.println("No cartridges found");
    --- End diff --
    
    Sys.outs need to be removed.


---
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] stratos pull request: Adding network partitions for CLI

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

    https://github.com/apache/stratos/pull/198#discussion_r23766317
  
    --- Diff: components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddNetworkPartitionCommand.java ---
    @@ -0,0 +1,174 @@
    +/**
    + *  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 org.apache.stratos.cli.commands;
    +
    +import org.apache.commons.cli.*;
    +import org.apache.stratos.cli.Command;
    +import org.apache.stratos.cli.RestCommandLineService;
    +import org.apache.stratos.cli.StratosCommandContext;
    +import org.apache.stratos.cli.exception.CommandException;
    +import org.apache.stratos.cli.utils.CliConstants;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.io.BufferedReader;
    +import java.io.FileReader;
    +import java.io.IOException;
    +
    +public class AddNetworkPartitionCommand implements Command<StratosCommandContext> {
    +
    +    private static final Logger logger = LoggerFactory.getLogger(AddNetworkPartitionCommand.class);
    +
    +    private final Options options;
    +
    +    public AddNetworkPartitionCommand(){
    +        options = constructOptions();
    +    }
    +
    +    private Options constructOptions() {
    +        final Options options = new Options();
    +
    +        Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
    +                "Network partition resource path");
    +        resourcePath.setArgName("resource path");
    +        options.addOption(resourcePath);
    +
    +        return options;
    +    }
    +    /**
    +     * @return The name of the command
    +     */
    +    @Override
    +    public String getName() {
    +        return "add-network-partition";
    +    }
    +
    +    /**
    +     * Information about the command
    +     *
    +     * @return The description of the command
    +     */
    +    @Override
    +    public String getDescription() {
    +        return "add network partition deployment";
    --- End diff --
    
    May be we can change text "add" to "Add".


---
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] stratos pull request: Adding network partitions for CLI

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

    https://github.com/apache/stratos/pull/198


---
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] stratos pull request: Adding network partitions for CLI

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

    https://github.com/apache/stratos/pull/198#discussion_r23768119
  
    --- Diff: components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java ---
    @@ -1130,4 +1134,57 @@ private void printError(String message, Throwable e) {
             // Log error
             log.error(message, e);
         }
    +
    +    // This method helps to add network partition definitions
    +    public void addNetworkPartition(String networkPartitionDefinition) throws CommandException {
    +        restClient.deployEntity(ENDPOINT_DEPLOY_NETWORK_PARTITION, networkPartitionDefinition, "network partition");
    +    }
    +
    +    // This method helps to remove network partitions
    +    public void removeNetworkPartition (String id) {
    +        restClient.deleteEntity(ENDPOINT_REMOVE_NETWORK_PARTITION.replace("{networkPartitionId}", id), id,
    +                "network-partition");
    +    }
    +
    +    /**
    +     * List network partitions
    +     * @throws CommandException
    +     */
    +    public void listNetworkPartitions() throws CommandException {
    +        try {
    +            Type listType = new TypeToken<ArrayList<NetworkPartitionBean>>() {
    +            }.getType();
    +            List<NetworkPartitionBean> networkPartitionsList = (List<NetworkPartitionBean>) restClient.listEntity(ENDPOINT_LIST_NETWORK_PARTITIONS,
    +                    listType, "network-partitions");
    +
    +            if ((networkPartitionsList == null) || (networkPartitionsList.size() == 0)) {
    +                System.out.println("No network partitions found");
    +                return;
    +            }
    +
    +            RowMapper<NetworkPartitionBean> networkPartitionMapper = new RowMapper<NetworkPartitionBean>() {
    +                public String[] getData(NetworkPartitionBean partition) {
    +                    String[] data = new String[3];
    +                    data[0] = partition.getId();
    +                    data[1] = (partition.getKubernetesClusterId() != null) ? partition.getKubernetesClusterId() : "";
    +                    data[2] = String.valueOf(partition.getPartitions().size());;
    +                    return data;
    +                }
    +            };
    +
    +            NetworkPartitionBean[] partitions = new NetworkPartitionBean[networkPartitionsList.size()];
    +            partitions = networkPartitionsList.toArray(partitions);
    +
    +            System.out.println("Network partitions found:");
    +            CliUtils.printTable(partitions, networkPartitionMapper, "PartitionId", "Kubernetes Cluster Id", "Partitions");
    +        } catch (Exception e) {
    +            String message = "Error in listing network partitions" + e;
    --- End diff --
    
    We don't need to append exception to the message. We can have our own message.
    
    Thanks


---
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] stratos pull request: Adding network partitions for CLI

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

    https://github.com/apache/stratos/pull/198#discussion_r23766401
  
    --- Diff: components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java ---
    @@ -1130,4 +1134,57 @@ private void printError(String message, Throwable e) {
             // Log error
             log.error(message, e);
         }
    +
    +    // This method helps to add network partition definitions
    --- End diff --
    
    Shall we use Java method header format for this?
    Thanks


---
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.
---