}
List<Container> toUpgrade = new ArrayList<Container>();
List<Container> same = new ArrayList<Container>();
for (String containerName : containerIds) {
Container container = FabricCommand.getContainer(fabricService, containerName);
// check first that all can upgrade
int num = ContainerUpgradeSupport.canUpgrade(version, container);
if (num < 0) {
throw new IllegalArgumentException("Container " + container.getId() + " already has a higher version " + container.getVersion()
+ " than the requested version " + version.getId() + ".");
} else if (num == 0) {
// same version
same.add(container);
} else {
// needs upgrade
toUpgrade.add(container);
}
}
// report same version
for (Container container : same) {
System.out.println("Container " + container.getId() + " is already at version " + version.getId());
}
// report and do upgrades
for (Container container : toUpgrade) {
Version oldVersion = container.getVersion();
// upgrade version first
container.setVersion(version);
// get the profile for version 1.1
log.info("Upgraded container {} from {} to {}", new Object[]{container.getId(), oldVersion.getId(), version.getId()});
System.out.println("Upgraded container " + container.getId() + " from version " + oldVersion.getId() + " to " + version.getId());
}
if (all) {
fabricService.setDefaultVersionId(version.getId());
System.out.println("Changed default version to " + version.getId());