//System.out.println(executeCommand("fabric:profile-list"));
ModuleContext moduleContext = RuntimeLocator.getRequiredRuntime().getModuleContext();
ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(moduleContext, FabricService.class);
try {
FabricService fabricService = fabricProxy.getService();
System.out.println(CommandSupport.executeCommand("fabric:version-create"));
System.out.println(CommandSupport.executeCommand("fabric:container-upgrade --all 1.1"));
Set<Container> containers = ContainerBuilder.create(2).withName("basic_ens_b").withProfiles("fabric").assertProvisioningResult().build(fabricService);
try {
LinkedList<Container> containerQueue = new LinkedList<Container>(containers);
LinkedList<Container> addedContainers = new LinkedList<Container>();
System.out.println(CommandSupport.executeCommand("fabric:version-create"));
System.out.println(CommandSupport.executeCommand("fabric:container-upgrade --all 1.2"));
Random rand = new Random();
for (int version = 3; version < 5; version++) {
ProvisionSupport.provisioningSuccess(Arrays.asList(fabricService.getContainers()), ProvisionSupport.PROVISION_TIMEOUT);
for (int e = 0; e < 3 && containerQueue.size() >= 2 && containerQueue.size() % 2 == 0; e++) {
Container cnt1 = containerQueue.removeFirst();
Container cnt2 = containerQueue.removeFirst();
addedContainers.add(cnt1);
addedContainers.add(cnt2);
EnsembleSupport.addToEnsemble(fabricService, cnt1, cnt2);
System.out.println(CommandSupport.executeCommand("config:proplist --pid io.fabric8.zookeeper"));
System.out.println(CommandSupport.executeCommand("fabric:container-list"));
System.out.println(CommandSupport.executeCommand("fabric:ensemble-list"));
ZooKeeperClusterService zooKeeperClusterService = ServiceLocator.awaitService(ZooKeeperClusterService.class);
org.junit.Assert.assertNotNull(zooKeeperClusterService);
List<String> ensembleContainersResult = zooKeeperClusterService.getEnsembleContainers();
org.junit.Assert.assertTrue(ensembleContainersResult.contains(cnt1.getId()));
org.junit.Assert.assertTrue(ensembleContainersResult.contains(cnt2.getId()));
ProvisionSupport.provisioningSuccess(Arrays.asList(fabricService.getContainers()), ProvisionSupport.PROVISION_TIMEOUT);
}
int index = rand.nextInt(addedContainers.size());
String randomContainer = addedContainers.get(index).getId();
System.out.println(CommandSupport.executeCommand("fabric:version-create 1." + version));
System.out.println(CommandSupport.executeCommand("fabric:container-upgrade 1." + version + " " + randomContainer));
ProvisionSupport.provisioningSuccess(Arrays.asList(fabricService.getContainers()), ProvisionSupport.PROVISION_TIMEOUT);
for (int e = 0; e < 3 && addedContainers.size() >= 2 && addedContainers.size() % 2 == 0; e++) {
Container cnt1 = addedContainers.removeFirst();
Container cnt2 = addedContainers.removeFirst();
containerQueue.add(cnt1);
containerQueue.add(cnt2);
EnsembleSupport.removeFromEnsemble(fabricService, cnt1, cnt2);
System.out.println(CommandSupport.executeCommand("config:proplist --pid io.fabric8.zookeeper"));
System.out.println(CommandSupport.executeCommand("fabric:container-list"));
System.out.println(CommandSupport.executeCommand("fabric:ensemble-list"));
ZooKeeperClusterService zooKeeperClusterService = ServiceLocator.awaitService(ZooKeeperClusterService.class);
org.junit.Assert.assertNotNull(zooKeeperClusterService);
List<String> ensembleContainersResult = zooKeeperClusterService.getEnsembleContainers();
org.junit.Assert.assertFalse(ensembleContainersResult.contains(cnt1.getId()));
org.junit.Assert.assertFalse(ensembleContainersResult.contains(cnt2.getId()));
ProvisionSupport.provisioningSuccess(Arrays.asList(fabricService.getContainers()), ProvisionSupport.PROVISION_TIMEOUT);
}
System.out.println(CommandSupport.executeCommand("fabric:container-rollback 1." + (version - 1) + " " + randomContainer));
}
} finally {
ContainerBuilder.stop(fabricService, containers);