use of io.fabric8.api.Profile in project fabric8 by jboss-fuse.
the class ContainerRegistrationTest method testContainerRegistration.
@Test
@SuppressWarnings("unchecked")
public void testContainerRegistration() throws Exception {
System.out.println(CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning"));
// System.out.println(executeCommand("shell:info"));
// System.out.println(executeCommand("fabric:info"));
// System.out.println(executeCommand("fabric:profile-list"));
BundleContext moduleContext = ServiceLocator.getSystemContext();
ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(moduleContext, FabricService.class);
try {
FabricService fabricService = fabricProxy.getService();
System.out.println(CommandSupport.executeCommand("fabric:profile-create --parent default child-profile"));
Assert.assertTrue(ProvisionSupport.profileAvailable("child-profile", "1.0", ProvisionSupport.PROVISION_TIMEOUT));
Set<Container> containers = ContainerBuilder.create(1, 1).withName("basic_cnt").withProfiles("child-profile").assertProvisioningResult().build(fabricService);
try {
Container cntA = containers.iterator().next();
System.out.println(CommandSupport.executeCommand("fabric:profile-edit --import-pid --pid org.apache.karaf.shell child-profile"));
System.out.println(CommandSupport.executeCommand("fabric:profile-edit --pid org.apache.karaf.shell/sshPort=8105 child-profile"));
System.out.println(CommandSupport.executeCommand("fabric:profile-edit --import-pid --pid org.apache.karaf.management child-profile"));
System.out.println(CommandSupport.executeCommand("fabric:profile-edit --pid org.apache.karaf.management/rmiServerPort=55555 child-profile"));
System.out.println(CommandSupport.executeCommand("fabric:profile-edit --pid org.apache.karaf.management/rmiRegistryPort=1100 child-profile"));
System.out.println(CommandSupport.executeCommand("fabric:profile-edit --pid org.apache.karaf.management/serviceUrl=service:jmx:rmi://localhost:55555/jndi/rmi://localhost:1099/karaf-" + cntA.getId() + " child-profile"));
String sshUrl = cntA.getSshUrl();
String jmxUrl = cntA.getJmxUrl();
long end = System.currentTimeMillis() + ProvisionSupport.PROVISION_TIMEOUT;
while (System.currentTimeMillis() < end && (!sshUrl.endsWith("8105") || !jmxUrl.contains("55555"))) {
Thread.sleep(1000L);
sshUrl = cntA.getSshUrl();
jmxUrl = cntA.getJmxUrl();
}
Assert.assertTrue("sshUrl ends with 8105, but was: " + sshUrl, sshUrl.endsWith("8105"));
Assert.assertTrue("jmxUrl contains 55555, but was: " + jmxUrl, jmxUrl.contains("55555"));
} finally {
ContainerBuilder.stop(fabricService, containers);
}
} finally {
fabricProxy.close();
}
}
use of io.fabric8.api.Profile in project fabric8 by jboss-fuse.
the class DeploymentAgentTest method testFeatureRepoResolution.
@Test
@SuppressWarnings("unchecked")
public void testFeatureRepoResolution() throws Exception {
CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning");
// We are just want to use a feature repository that is not part of the distribution.
CommandSupport.executeCommand("fabric:profile-create --parent feature-camel test-profile");
CommandSupport.executeCommand("fabric:version-create --parent 1.0 1.1");
CommandSupport.executeCommand("fabric:profile-edit --repository mvn:io.fabric8.examples.fabric-camel-dosgi/features/" + System.getProperty("fabric.version") + "/xml/features test-profile 1.1");
CommandSupport.executeCommand("fabric:profile-edit --feature fabric-dosgi test-profile 1.1");
// We remove all repositories from agent config but the maven central to rely on the fabric-maven-proxy.
// Also remove local repository
CommandSupport.executeCommand("fabric:profile-edit --pid io.fabric8.agent/org.ops4j.pax.url.mvn.repositories=http://repo1.maven.org/maven2@id=m2central default 1.1");
CommandSupport.executeCommand("fabric:profile-edit --pid test-profile 1.1");
BundleContext moduleContext = ServiceLocator.getSystemContext();
ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(moduleContext, FabricService.class);
try {
FabricService fabricService = fabricProxy.getService();
Set<Container> containers = ContainerBuilder.create().withName("smoke_cnt_a").withProfiles("test-profile").assertProvisioningResult().build(fabricService);
try {
// We want to remove all repositories from fabric-agent.
for (Container container : containers) {
CommandSupport.executeCommand("fabric:container-upgrade 1.1 " + container.getId());
System.out.flush();
}
ProvisionSupport.provisioningSuccess(containers, ProvisionSupport.PROVISION_TIMEOUT);
CommandSupport.executeCommand("fabric:container-list");
for (Container container : containers) {
CommandSupport.executeCommand("fabric:container-connect -u admin -p admin " + container.getId() + " osgi:list");
CommandSupport.executeCommand("fabric:container-connect -u admin -p admin " + container.getId() + " config:proplist --pid org.ops4j.pax.url.mvn");
System.out.flush();
}
} finally {
ContainerBuilder.stop(fabricService, containers);
}
} finally {
fabricProxy.close();
}
}
use of io.fabric8.api.Profile in project fabric8 by jboss-fuse.
the class ProfileEditTest method deployment.
@Deployment
@StartLevelAware(autostart = true)
public static Archive<?> deployment() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "profile-edit-test.jar");
archive.addPackage(CommandSupport.class.getPackage());
archive.setManifest(new Asset() {
@Override
public InputStream openStream() {
OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
builder.addBundleManifestVersion(2);
builder.addBundleSymbolicName(archive.getName());
builder.addBundleVersion("1.0.0");
builder.addImportPackages(ServiceLocator.class, FabricService.class);
builder.addImportPackages("io.fabric8.git");
builder.addImportPackages(AbstractCommand.class, Action.class);
builder.addImportPackage("org.apache.felix.service.command;status=provisional");
builder.addImportPackages(ConfigurationAdmin.class, ServiceTracker.class, Logger.class);
return builder.openStream();
}
});
return archive;
}
use of io.fabric8.api.Profile 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.Profile 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;
}
Aggregations