Search in sources :

Example 61 with FabricService

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();
    }
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) FabricException(io.fabric8.api.FabricException)

Example 62 with FabricService

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);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) FabricException(io.fabric8.api.FabricException) FabricService(io.fabric8.api.FabricService) CreateContainerBasicOptions(io.fabric8.api.CreateContainerBasicOptions) HashSet(java.util.HashSet) BundleContext(org.osgi.framework.BundleContext)

Example 63 with FabricService

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();
    }
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) CreateContainerOptions(io.fabric8.api.CreateContainerOptions) Test(org.junit.Test)

Example 64 with FabricService

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();
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) NFileEntity(org.apache.http.nio.entity.NFileEntity) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) CuratorFramework(org.apache.curator.framework.CuratorFramework) Random(java.util.Random) FabricService(io.fabric8.api.FabricService) File(java.io.File) ContainerProxy(io.fabric8.itests.paxexam.support.ContainerProxy) Test(org.junit.Test)

Example 65 with FabricService

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"));
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) Test(org.junit.Test)

Aggregations

FabricService (io.fabric8.api.FabricService)80 Container (io.fabric8.api.Container)76 Test (org.junit.Test)52 Profile (io.fabric8.api.Profile)50 BundleContext (org.osgi.framework.BundleContext)29 Version (io.fabric8.api.Version)24 ArrayList (java.util.ArrayList)21 ProfileService (io.fabric8.api.ProfileService)19 HashMap (java.util.HashMap)16 CuratorFramework (org.apache.curator.framework.CuratorFramework)16 HashSet (java.util.HashSet)14 Map (java.util.Map)13 FabricException (io.fabric8.api.FabricException)12 IOException (java.io.IOException)12 ContainerProxy (io.fabric8.itests.paxexam.support.ContainerProxy)11 Ignore (org.junit.Ignore)10 File (java.io.File)9 LinkedList (java.util.LinkedList)9 Path (javax.ws.rs.Path)8 FabricRequirements (io.fabric8.api.FabricRequirements)7