use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class FabricEnsembleTest method addToEnsemble.
public void addToEnsemble(FabricService fabricService, Container... containers) throws Exception {
StringBuilder sb = new StringBuilder();
sb.append("fabric:ensemble-add --force --migration-timeout 240000 ");
for (Container c : containers) {
sb.append(c.getId()).append(" ");
}
doWithEnsemble(fabricService, sb.toString());
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class FabricFeaturesTest method assertProvisionedFeature.
/**
* Adds a feature to the profile and tests it on the container.
* <p>Note:</p> Before and after the test the container moves to default profile.
*/
protected void assertProvisionedFeature(FabricService fabricService, CuratorFramework curator, Set<? extends Container> containers, String featureNames, String profileName, final String expectedSymbolicNames) throws Exception {
StringBuilder sb = new StringBuilder();
sb.append("[ ");
for (Container container : containers) {
sb.append(container.getId()).append(" ");
}
sb.append("]");
System.out.println("Testing profile:" + profileName + " on container:" + sb.toString() + " by adding feature:" + featureNames);
Version version = fabricService.getRequiredDefaultVersion();
Profile defaultProfile = version.getRequiredProfile("default");
Profile targetProfile = version.getRequiredProfile(profileName);
for (Container container : containers) {
// We set container to default to clean the container up.
container.setProfiles(new Profile[] { defaultProfile });
}
Provision.containerStatus(containers, PROVISION_TIMEOUT);
for (String featureName : featureNames.split(" ")) {
System.out.println(executeCommand("fabric:profile-edit --feature " + featureName + " " + targetProfile.getId()));
}
System.out.println(executeCommand("fabric:profile-display " + profileName));
for (Container container : containers) {
// Test the modified profile.
setData(curator, ZkPath.CONTAINER_PROVISION_RESULT.getPath(container.getId()), "switching profile");
container.setProfiles(new Profile[] { targetProfile });
}
Provision.containerStatus(containers, PROVISION_TIMEOUT);
System.out.println(executeCommand("fabric:container-list"));
Assert.assertTrue(Provision.waitForCondition(containers, new ContainerCondition() {
@Override
public Boolean checkConditionOnContainer(Container c) {
for (String symbolicName : expectedSymbolicNames.split(" ")) {
String bundles = executeCommand("container-connect -u admin -p admin " + c.getId() + " osgi:list -s -t 0 | grep " + symbolicName);
if (bundles != null) {
return bundles.contains(symbolicName);
}
}
return false;
}
}, PROVISION_TIMEOUT));
for (Container container : containers) {
// We set the container to default to clean up the profile.
if (!defaultProfile.equals(targetProfile)) {
setData(curator, ZkPath.CONTAINER_PROVISION_RESULT.getPath(container.getId()), "switching profile");
}
container.setProfiles(new Profile[] { defaultProfile });
}
Provision.containerStatus(containers, PROVISION_TIMEOUT);
for (String featureName : featureNames.split(" ")) {
System.out.println(executeCommand("fabric:profile-edit --delete --feature " + featureName + " " + targetProfile.getId()));
}
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class FabricTestSupport method destroyChildContainer.
private void destroyChildContainer(FabricService fabricService, CuratorFramework curator, String name) throws InterruptedException {
try {
// Wait for zookeeper service to become available.
Thread.sleep(DEFAULT_WAIT);
// We need this because getContainer will create a container object if container doesn't exists.
if (ZooKeeperUtils.exists(curator, ZkPath.CONTAINER.getPath(name)) != null) {
Container container = fabricService.getContainer(name);
// We want to go through container destroy method so that cleanup methods are properly invoked.
container.destroy();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class FabricTestSupport method containerSetProfile.
/**
* Cleans a containers profile by switching to default profile and resetting the profile.
*/
private boolean containerSetProfile(FabricService fabricService, CuratorFramework curator, String containerName, String profileName, Boolean waitForProvision) throws Exception {
System.out.println("Switching profile: " + profileName + " on container:" + containerName);
Container container = fabricService.getContainer(containerName);
Version version = container.getVersion();
Profile[] profiles = new Profile[] { version.getRequiredProfile(profileName) };
Profile[] currentProfiles = container.getProfiles();
Arrays.sort(profiles);
Arrays.sort(currentProfiles);
boolean same = true;
if (profiles.length != currentProfiles.length) {
same = false;
} else {
for (int i = 0; i < currentProfiles.length; i++) {
if (!currentProfiles[i].equals(profiles[i])) {
same = false;
}
}
}
if (!same && waitForProvision) {
// This is required so that waitForProvisionSuccess doesn't retrun before the deployment agent kicks in.
ZooKeeperUtils.setData(curator, ZkPath.CONTAINER_PROVISION_RESULT.getPath(containerName), "switching profile");
container.setProfiles(profiles);
Provision.containersStatus(Arrays.asList(container), "success", PROVISION_TIMEOUT);
}
return same;
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class SshContainerBuilder method build.
/**
* Create the containers.
*/
@Override
public Set<ContainerProxy> build() {
BundleContext bundleContext = ContainerBuilder.getBundleContext();
if (getOptionsBuilder().getHost() == null || getOptionsBuilder().getHost().isEmpty()) {
FabricService fabricService = ServiceLocator.awaitService(bundleContext, FabricService.class);
getOptionsBuilder().zookeeperUrl(fabricService.getZookeeperUrl()).zookeeperPassword("admin").proxyUri(fabricService.getMavenRepoURI());
String hostProperty = System.getProperty(SSH_HOSTS_PROPERTY);
String userProperty = System.getProperty(SSH_USERS_PROPERTY);
String passwordProperty = System.getProperty(SSH_PASSWORD_PROPERTY);
String resolverProperty = System.getProperty(SSH_RESOLVER_PROPERTY, ZkDefs.DEFAULT_RESOLVER);
if (resolverProperty.isEmpty()) {
resolverProperty = ZkDefs.DEFAULT_RESOLVER;
}
String numberOfContainersProperty = System.getProperty(CONTAINER_NUMBER_PROPERTY, "1");
int numberOfContainers = Integer.parseInt(numberOfContainersProperty);
String[] hosts = null;
String[] usernames = null;
String[] passwords = null;
if (hostProperty != null && !hostProperty.isEmpty()) {
hosts = hostProperty.replaceAll(" ", "").split(",");
}
if (userProperty != null && !userProperty.isEmpty()) {
usernames = userProperty.replaceAll(" ", "").split(",");
}
if (passwordProperty != null && !passwordProperty.isEmpty()) {
passwords = passwordProperty.replaceAll(" ", "").split(",");
}
int numberOfHosts = hosts.length;
int containersPerHost = numberOfContainers > 1 ? numberOfContainers / numberOfHosts : 1;
List<CreateSshContainerOptions.Builder> optionsList = new ArrayList<CreateSshContainerOptions.Builder>();
for (int i = 0; i < hosts.length; i++) {
try {
CreateSshContainerOptions.Builder hostOpts = getOptionsBuilder().clone();
hostOpts.number(containersPerHost).host(hosts[i]);
if (hostOpts.getNumber() > 1) {
hostOpts.name(hostOpts.getName() + "-" + i + "-");
} else {
hostOpts.name(hostOpts.getName() + i);
}
hostOpts.resolver(resolverProperty);
if (usernames.length > i) {
hostOpts.setUsername(usernames[i]);
}
if (passwords.length > i) {
hostOpts.setPassword(passwords[i]);
}
optionsList.add(hostOpts);
} catch (CloneNotSupportedException e) {
throw FabricException.launderThrowable(e);
}
}
return super.build(optionsList);
} else {
return super.build();
}
}
Aggregations