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 java.util.List;
 
 import  org.apache.felix.gogo.commands.Argument;
 import  org.apache.felix.gogo.commands.Command;
 import  org.apache.felix.gogo.commands.Option;
 import  org.apache.karaf.shell.console.AbstractAction;
 
 @Command(name = ., scope = ., description = ., detailedDescription = "classpath:containerUpgrade.txt")
 public final class ContainerRollbackAction extends AbstractAction {
 
     @Option(name = "--all", description = "Roll back all containers")
     private boolean all;
     @Argument(index = 0, name = "version", description = "The version to roll back to.", required = true)
     private String version;
     @Argument(index = 1, name = "container", description = "The list of containers to roll back. An empty list implies the current container.", required = false, multiValued = true)
     private List<StringcontainerIds;
 
     protected final FabricService fabricService;
 
     ContainerRollbackAction(FabricService fabricService) {
         this. = fabricService;
     }
 
     @Override
     protected Object doExecute() throws Exception {
         FabricValidations.validateContainerNames();
 
         // check and validate version
         Version version = .getVersion(this.);
 
         if ( == null || .isEmpty()) {
             if () {
                  = new ArrayList<String>();
                 for (Container container : .getContainers()) {
                     .add(container.getId());
                 }
             } else {
                  = Arrays.asList(.getCurrentContainer().getId());
             }
         } else {
             if () {
                 throw new IllegalArgumentException("Can not use --all with a list of containers simultaneously");
             }
         }
 
         List<ContainertoRollback = new ArrayList<Container>();
         List<Containersame = new ArrayList<Container>();
         for (String containerName : ) {
             Container container = FabricCommand.getContainer(containerName);
 
             // check first that all can rollback
             int num = ContainerUpgradeSupport.canRollback(versioncontainer);
             if (num < 0) {
                 throw new IllegalArgumentException("Container " + container.getId() + " has already lower version " + container.getVersion()
                         + " than the requested version " + version + " to rollback.");
             } else if (num == 0) {
                 // same version
                 same.add(container);
             } else {
                 // needs rollback
                 toRollback.add(container);
             }
         }
 
         // report same version
         for (Container container : same) {
             ..println("Container " + container.getId() + " is already version " + version);
         }
 
         // report and do rollbacks
         for (Container container : toRollback) {
             Version oldVersion = container.getVersion();
             // rollback version first
            container.setVersion(version);
            log.debug("Rolled back container {} from {} to {}"new Object[]{containeroldVersionversion});
            ..println("Rolled back container " + container.getId() + " from version " + oldVersion + " to " + version);
        }
		if () {
			..println("Changed default version to " + version);
		}
        return null;
    }
New to GrepCode? Check out our FAQ X