use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class ContainerBuilder method destroy.
/**
* Destroy the given containers
*/
public static void destroy(Set<? extends Container> containers) {
ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(getBundleContext(), FabricService.class);
try {
FabricService fabricService = fabricProxy.getService();
for (Container aux : containers) {
try {
// We want to use the latest metadata
Container container = fabricService.getContainer(aux.getId());
container.destroy(true);
} catch (Exception ex) {
// noop
}
}
} finally {
fabricProxy.close();
}
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class ContainerBuilder method buildInternal.
private Set<ContainerProxy> buildInternal(Collection<B> buildersList) {
Set<ContainerProxy> containers = new HashSet<ContainerProxy>();
BundleContext bundleContext = getBundleContext();
ServiceLocator.awaitService(getBundleContext(), FabricComplete.class);
synchronizeGitRepositories();
FabricService fabricService = fabricServiceServiceProxy.getService();
CompletionService<Set<ContainerProxy>> completionService = new ExecutorCompletionService<Set<ContainerProxy>>(executorService);
int tasks = 0;
for (B builder : buildersList) {
builder.profiles(profileNames);
if (!builder.isEnsembleServer()) {
builder.zookeeperUrl(fabricService.getZookeeperUrl());
CreateContainerBasicOptions options = builder.build();
ServiceLocator.awaitService(bundleContext, ContainerProvider.class, "(fabric.container.protocol=" + options.getProviderType() + ")", CREATE_TIMEOUT, TimeUnit.MILLISECONDS);
completionService.submit(new CreateContainerTask(fabricServiceServiceProxy, options));
tasks++;
}
}
try {
for (int i = 0; i < tasks; i++) {
Future<Set<ContainerProxy>> futureContainerSet = completionService.poll(CREATE_TIMEOUT, TimeUnit.MILLISECONDS);
Set<ContainerProxy> containerSet = futureContainerSet.get();
containers.addAll(containerSet);
}
try {
if (waitForProvisioning) {
Provision.containerStatus(containers, provisionTimeOut);
}
if (assertProvisioningResult) {
Provision.provisioningSuccess(containers, provisionTimeOut, ContainerCallback.DISPLAY_ALL);
}
} catch (Exception e) {
throw FabricException.launderThrowable(e);
}
} catch (Exception e) {
throw FabricException.launderThrowable(e);
}
return Collections.unmodifiableSet(containers);
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class CreateSshContainerTest method testSshContainerProvider.
@Test
public void testSshContainerProvider() throws Throwable {
Assume.assumeTrue(isReady());
System.out.println(executeCommand("fabric:create -n --wait-for-provisioning"));
// System.out.println(executeCommand("shell:info"));
// System.out.println(executeCommand("fabric:info"));
// System.out.println(executeCommand("fabric:profile-list"));
ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
try {
FabricService fabricService = fabricProxy.getService();
CreateContainerOptions options = CreateSshContainerOptions.builder().name("ssh1").host(host).port(Integer.parseInt(port)).username(username).password(password).build();
CreateContainerMetadata[] metadata = fabricService.createContainers(options);
assertNotNull(metadata);
assertEquals(1, metadata.length);
if (metadata[0].getFailure() != null) {
throw metadata[0].getFailure();
}
assertTrue("Expected successful creation of remote ssh container", metadata[0].isSuccess());
assertNotNull("Expected successful creation of remote ssh container", metadata[0].getContainer());
Provision.containersStatus(Arrays.asList(metadata[0].getContainer()), "success", PROVISION_TIMEOUT);
System.out.println(executeCommand("fabric:container-list -v"));
System.out.println(executeCommand("fabric:container-resolver-list"));
Container ssh1 = fabricService.getContainer("ssh1");
assertTrue(ssh1.isAlive());
createAndAssertChildContainer(fabricService, "ssh2", "ssh1", "default");
// Stop & Start Remote Child
Container ssh2 = fabricService.getContainer("ssh2");
ssh2.stop();
assertFalse(ssh2.isAlive());
ssh2.start();
Provision.containersStatus(Arrays.asList(ssh2), "success", PROVISION_TIMEOUT);
assertTrue(ssh2.isAlive());
ssh2.stop();
// Try stopping and starting the remote container.
ssh1.stop();
assertFalse(ssh1.isAlive());
System.out.println(executeCommand("fabric:container-list -v"));
ssh1.start();
Provision.containersStatus(Arrays.asList(ssh1), "success", PROVISION_TIMEOUT);
System.out.println(executeCommand("fabric:container-list -v"));
assertTrue(ssh1.isAlive());
} finally {
fabricProxy.close();
}
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class FabricMavenProxyTest method testUpload.
@Test
public void testUpload() throws Exception {
String featureLocation = System.getProperty("feature.location");
System.out.println("Testing with feature from:" + featureLocation);
System.out.println(executeCommand("fabric:create -n --wait-for-provisioning"));
// System.out.println(executeCommand("shell:info"));
// System.out.println(executeCommand("fabric:info"));
// System.out.println(executeCommand("fabric:profile-list"));
ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
try {
Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy, 2).withName("maven").withProfiles("fabric").waitForProvisioning(10 * 60 * 1000L).assertProvisioningResult().build();
try {
List<String> uploadUrls = new ArrayList<String>();
ServiceProxy<CuratorFramework> curatorProxy = ServiceProxy.createServiceProxy(bundleContext, CuratorFramework.class);
try {
CuratorFramework curator = curatorProxy.getService();
List<String> children = ZooKeeperUtils.getChildren(curator, ZkPath.MAVEN_PROXY.getPath("upload"));
for (String child : children) {
String uploadeUrl = ZooKeeperUtils.getSubstitutedPath(curator, ZkPath.MAVEN_PROXY.getPath("upload") + "/" + child);
uploadUrls.add(uploadeUrl);
}
} finally {
curatorProxy.close();
}
// Pick a random maven proxy from the list.
Random random = new Random();
int index = random.nextInt(uploadUrls.size());
String targetUrl = uploadUrls.get(index);
String uploadUrl = targetUrl + "itest/itest/1.0/itest-1.0-features.xml";
System.out.println("Using URI: " + uploadUrl);
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin", "admin"));
CloseableHttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build();
HttpPut put = new HttpPut(uploadUrl);
NFileEntity entity = new NFileEntity(new File(featureLocation), ContentType.TEXT_XML);
put.setEntity(entity);
HttpResponse response = client.execute(put);
System.out.println("Response:" + response.getStatusLine());
Assert.assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 202);
System.out.println(executeCommand("fabric:profile-edit --repository mvn:itest/itest/1.0/xml/features default"));
System.out.println(executeCommand("fabric:profile-edit --feature example-cbr default"));
Provision.containerStatus(containers, PROVISION_TIMEOUT);
} finally {
ContainerBuilder.destroy(containers);
}
} finally {
fabricProxy.close();
}
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class FabricCreateCommandTest method testLocalFabricCluster.
@Test
public void testLocalFabricCluster() throws Exception {
CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning");
FabricService fabricService = ServiceLocator.getRequiredService(FabricService.class);
Container[] containers = fabricService.getContainers();
Assert.assertNotNull("Containers not null", containers);
// Test that a provided default password exists
ConfigurationAdmin configurationAdmin = ServiceLocator.getRequiredService(ConfigurationAdmin.class);
org.osgi.service.cm.Configuration configuration = configurationAdmin.getConfiguration(io.fabric8.api.Constants.ZOOKEEPER_CLIENT_PID);
Dictionary<String, Object> dictionary = configuration.getProperties();
Assert.assertEquals("Expected provided zookeeper password", PasswordEncoder.encode(ADMIN_PASSWORD), dictionary.get("zookeeper.password"));
}
Aggregations