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.openshift.commands;
 
 import java.net.URI;
 import java.util.List;
 
 import  org.apache.felix.gogo.commands.Argument;
 import  org.apache.felix.gogo.commands.Command;
 import  org.apache.felix.gogo.commands.Option;
 
 @Command(name = "container-create-openshift", scope = "fabric", description = "Creates one or more new containers on Openshift")
 
     private static final Pattern ALLOWED_NAMES_PATTERN = Pattern.compile("[a-z0-9]+");
 
     @Option(name = "--server-url", required = false, description = "The url to the openshift server.")
     String serverUrl;
 
     @Option(name = "--login", required = false, description = "The login name to use.")
     String login;
 
     @Option(name = "--password", required = false, description = "The password to use.")
     String password;
 
     @Option(name = "--proxy-uri", description = "The Maven proxy URL to use")
     private URI proxyUri;
 
     @Argument(index = 0, required = true, description = "The name of the container to be created. When creating multiple containers it serves as a prefix")
     protected String name;
 
     @Argument(index = 1, required = false, description = "The number of containers that should be created")
     protected int number = 0;
 
     ContainerCreateOpenshiftAction(FabricService fabricService) {
         setFabricService(fabricService);
     }
 
     @Override
     protected Object doExecute() throws Exception {
         // validate input before creating containers
         preCreateContainer();
         FabricValidations.validateProfileNames();
 
         CreateOpenshiftContainerOptions.Builder builder = CreateOpenshiftContainerOptions.builder()
                 .name()
                 .serverUrl()
                 .login()
                 .password()
                 .version()
                 .ensembleServer()
                 .zookeeperUrl(.getZookeeperUrl())
                 .proxyUri( != null ?  : .getMavenRepoURI())
                 .profiles(getProfileNames())
                 .dataStoreProperties(getDataStoreProperties())
                 .dataStoreType( != null &&  ?  : .getDataStore().getType());
 
         CreateContainerMetadata[] metadatas = .createContainers(builder.build());
 
         if ( && metadatas != null && metadatas.length > 0 && metadatas[0].isSuccess()) {
             ShellUtils.storeZookeeperPassword(session, metadatas[0].getCreateOptions().getZookeeperPassword());
         }
         // display containers
         displayContainers(metadatas);
         return null;
     }
 
     protected void displayContainers(CreateContainerMetadata[] metadatas) {
         List<CreateContainerMetadatasuccess = new ArrayList<CreateContainerMetadata>();
         List<CreateContainerMetadatafailures = new ArrayList<CreateContainerMetadata>();
         for (CreateContainerMetadata metadata : metadatas) {
             (metadata.isSuccess() ? success : failures).add(metadata);
         }
         if (success.size() > 0) {
             ..println("The following containers have been created successfully:");
             for (CreateContainerMetadata m : success) {
                ..println("\t" + m.toString());
            }
        }
        if (failures.size() > 0) {
            ..println("The following containers have failed:");
            for (CreateContainerMetadata m : failures) {
                ..println("\t" + m.getContainerName() + ": " + m.getFailure().getMessage());
            }
        }
    }

    
Validates the container name according to OpenShift naming rules.

Throws:
IllegalArgumentException if the container name is invalid.
    protected void validateOpenShiftContainerName(String containerName) {
        boolean valid = containerName != null && !containerName.isEmpty() && .matcher(containerName).matches();
        if (!valid) {
            throw new IllegalArgumentException("Container name '" + containerName + "' is invalid");
        }
    }
New to GrepCode? Check out our FAQ X