Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2014 Red Hat, Inc. Red Hat 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 io.fabric8.commands;
 
 
 import  org.apache.felix.gogo.commands.Argument;
 import  org.apache.felix.gogo.commands.Command;
 import  org.apache.felix.gogo.commands.Option;
 
 import static io.fabric8.utils.FabricValidations.validateProfileNames;
 
 @Command(name = ., scope = ., description = ., detailedDescription = "classpath:containerCreateChild.txt")
 
     @Option(name = "--jmx-user", multiValued = false, required = false, description = "The jmx user name of the parent container.")
     protected String username;
     @Option(name = "--jmx-password", multiValued = false, required = false, description = "The jmx password of the parent container.")
     protected String password;
 
     @Argument(index = 0, required = true, description = "Parent containers ID")
     protected String parent;
     @Argument(index = 1, required = true, description = "The name of the containers to be created. When creating multiple containers it serves as a prefix")
     protected String name;
     @Argument(index = 2, required = false, description = "The number of containers that should be created")
     protected int number = 0;
 
     ContainerCreateChildAction(FabricService fabricServiceZooKeeperClusterService clusterService) {
         super(fabricServiceclusterService);
     }
 
     @Override
     protected Object doExecute() throws Exception {
         CreateContainerMetadata[] metadatas = null;
         validateProfileNames();
 
         // validate input before creating containers
         preCreateContainer();
 
         String jmxUser =  != null ?  : ShellUtils.retrieveFabricUser(session);
         String jmxPassword =  != null ?  : ShellUtils.retrieveFabricUserPassword(session);
 
         // okay create child container
         String url = "child://" + ;
         CreateChildContainerOptions.Builder builder = CreateChildContainerOptions.builder()
                 .name()
                 .parent()
                 .bindAddress()
                 .resolver()
                 .manualIp()
                 .ensembleServer()
                 .number()
                 .zookeeperUrl(.getZookeeperUrl())
                 .zookeeperPassword(.getZookeeperPassword())
                 .jvmOpts()
                 .jmxUser(jmxUser)
                 .jmxPassword(jmxPassword)
                 .version()
                 .profiles(getProfileNames())
                 .dataStoreProperties(getDataStoreProperties())
                 .dataStoreType(.getDataStore().getType());
 
         try {
             metadatas = .createContainers(builder.build());
             rethrowAuthenticationErrors(metadatas);
             ShellUtils.storeFabricCredentials(session, jmxUserjmxPassword);
         } catch (FabricAuthenticationException ex) {
             //If authentication fails, prompts for credentials and try again.
              = null;
              = null;
             promptForJmxCredentialsIfNeeded();
             metadatas = .createContainers(builder.jmxUser().jmxPassword().build());
             ShellUtils.storeFabricCredentials(session, );
         }
 
         // display containers
         displayContainers(metadatas);
         return null;
     }
    @Override
    protected void preCreateContainer(String name) {
        super.preCreateContainer(name);
        // validate number is not out of bounds
        if ( < 0 ||  > 99) {
            throw new IllegalArgumentException("The number of containers must be between 1 and 99.");
        }
        if ( &&  > 1) {
            throw new IllegalArgumentException("Can not create a new ZooKeeper ensemble on multiple containers.  Create the containers first and then use the fabric:create command instead.");
        }
    }
    private void promptForJmxCredentialsIfNeeded() throws IOException {
        // If the username was not configured via cli, then prompt the user for the values
        if ( == null) {
            log.debug("Prompting user for jmx login");
             = ShellUtils.readLine(session, "Jmx Login for " +  + ": "false);
        }
        if ( == null) {
             = ShellUtils.readLine(session, "Jmx Password for " +  + ": "true);
        }
    }
New to GrepCode? Check out our FAQ X