Search in sources :

Example 81 with io.fabric8.kubernetes.api.model

use of io.fabric8.kubernetes.api.model in project fabric8 by jboss-fuse.

the class MavenProxyServletSupportTest method testUploadWithMimeMultipartFormData.

@Test
public void testUploadWithMimeMultipartFormData() throws Exception {
    new File("target/maven/proxy/tmp/multipart").mkdirs();
    System.setProperty("karaf.data", new File("target").getCanonicalPath());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    JarOutputStream jas = new JarOutputStream(baos);
    addEntry(jas, "META-INF/MANIFEST.MF", "Manifest-Version: 1.0\n".getBytes());
    addEntry(jas, "META-INF/maven/io.fabric8/mybundle/pom.properties", "groupId=io.fabric8\nartifactId=mybundle\nversion=1.0\n".getBytes());
    jas.close();
    byte[] jarBytes = baos.toByteArray();
    RuntimeProperties props = new MockRuntimeProperties();
    MavenResolver resolver = EasyMock.createMock(MavenResolver.class);
    MavenUploadProxyServlet servlet = new MavenUploadProxyServlet(resolver, props, projectDeployer, new File("target/upload"), 0);
    servlet.setFileItemFactory(new DiskFileItemFactory(0, new File("target/maven/proxy/tmp/multipart")));
    HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
    HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class);
    FilePart part = new FilePart("file[]", new ByteArrayPartSource("mybundle-1.0.jar", jarBytes));
    MultipartRequestEntity entity = new MultipartRequestEntity(new Part[] { part }, new HttpMethodParams());
    final ByteArrayOutputStream requestBytes = new ByteArrayOutputStream();
    entity.writeRequest(requestBytes);
    final byte[] multipartRequestBytes = requestBytes.toByteArray();
    EasyMock.expect(request.getPathInfo()).andReturn("/mybundle-1.0.jar");
    EasyMock.expect(request.getHeader(MavenProxyServletSupport.LOCATION_HEADER)).andReturn(null);
    EasyMock.expect(request.getParameter("profile")).andReturn("my");
    EasyMock.expect(request.getParameter("version")).andReturn("1.0");
    EasyMock.expect(request.getContentType()).andReturn(entity.getContentType()).anyTimes();
    EasyMock.expect(request.getHeader("Content-length")).andReturn(Long.toString(entity.getContentLength())).anyTimes();
    EasyMock.expect(request.getContentLength()).andReturn((int) entity.getContentLength()).anyTimes();
    EasyMock.expect(request.getCharacterEncoding()).andReturn("ISO-8859-1").anyTimes();
    Capture<String> location = EasyMock.newCapture(CaptureType.ALL);
    response.setStatus(HttpServletResponse.SC_ACCEPTED);
    EasyMock.expect(request.getInputStream()).andReturn(new ServletInputStream() {

        private int pos = 0;

        @Override
        public int read() throws IOException {
            return pos >= multipartRequestBytes.length ? -1 : (multipartRequestBytes[pos++] & 0xFF);
        }

        @Override
        public boolean isFinished() {
            return false;
        }

        @Override
        public boolean isReady() {
            return true;
        }

        @Override
        public void setReadListener(ReadListener readListener) {
        }
    });
    Capture<ProjectRequirements> requirementsCapture = EasyMock.newCapture(CaptureType.FIRST);
    EasyMock.expect(projectDeployer.deployProject(EasyMock.capture(requirementsCapture), EasyMock.eq(true))).andReturn(null);
    EasyMock.replay(resolver, request, response, projectDeployer);
    servlet.doPut(request, response);
    FileInputStream fis = new FileInputStream("target/upload/io.fabric8/mybundle/1.0/mybundle-1.0.jar");
    ByteArrayOutputStream storedBundleBytes = new ByteArrayOutputStream();
    IOUtils.copy(fis, storedBundleBytes);
    fis.close();
    Assert.assertArrayEquals(jarBytes, storedBundleBytes.toByteArray());
    ProjectRequirements pr = requirementsCapture.getValue();
    List<String> bundles = pr.getBundles();
    assertThat(bundles.size(), equalTo(1));
    assertThat(bundles.get(0), equalTo("mvn:io.fabric8/mybundle/1.0"));
    assertThat(pr.getProfileId(), equalTo("my"));
    assertThat(pr.getVersion(), equalTo("1.0"));
    assertThat(pr.getGroupId(), nullValue());
    assertThat(pr.getArtifactId(), nullValue());
    EasyMock.verify(resolver, request, response, projectDeployer);
}
Also used : ReadListener(javax.servlet.ReadListener) ByteArrayPartSource(org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletInputStream(javax.servlet.ServletInputStream) MavenResolver(io.fabric8.maven.MavenResolver) ProjectRequirements(io.fabric8.deployer.dto.ProjectRequirements) AbstractRuntimeProperties(io.fabric8.api.scr.AbstractRuntimeProperties) RuntimeProperties(io.fabric8.api.RuntimeProperties) JarOutputStream(java.util.jar.JarOutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) HttpMethodParams(org.apache.commons.httpclient.params.HttpMethodParams) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) MultipartRequestEntity(org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity) FilePart(org.apache.commons.httpclient.methods.multipart.FilePart) FileInputStream(java.io.FileInputStream) File(java.io.File)

Example 82 with io.fabric8.kubernetes.api.model

use of io.fabric8.kubernetes.api.model in project fabric8 by jboss-fuse.

the class MavenProxySnapshotResolutionTest method snapshotIsAvailableInTwoDefaultRepositories.

@Test
public void snapshotIsAvailableInTwoDefaultRepositories() throws IOException, InvalidMavenArtifactRequest {
    File defaultRepository1 = initFileRepository("dr1");
    File defaultRepository2 = initFileRepository("dr2");
    MavenResolver resolver = new ResolverBuilder().withDefaultRepositories(Arrays.asList(defaultRepository1, defaultRepository2)).build();
    MavenDownloadProxyServlet servlet = new MavenDownloadProxyServlet(resolver, runtime, null, 1, 0);
    servlet.start();
    mvnInstall(defaultRepository1, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("10:00"), "a");
    mvnInstall(defaultRepository2, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("11:00"), "b");
    File file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
    Metadata metadata = readMetadata(file);
    assertThat("Resolution done in first default repository, even if second one has newer artifact", metadata.getVersioning().getSnapshotVersions().get(0).getUpdated(), is("20170101100000"));
}
Also used : MavenResolver(io.fabric8.maven.MavenResolver) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) File(java.io.File) Test(org.junit.Test)

Example 83 with io.fabric8.kubernetes.api.model

use of io.fabric8.kubernetes.api.model in project fabric8 by jboss-fuse.

the class FabricDetectingGateway method deactivate.

@Deactivate
void deactivate() throws Exception {
    JMXUtils.unregisterMBean(mbeanServer, new ObjectName("io.fabric8.gateway:type=DetectingGateway"));
    deactivateComponent();
    if (detectingGateway != null) {
        cache.destroy();
        detectingGateway.destroy();
        detectingGateway = null;
    }
    try {
        shutdownTacker.shutdown(new Runnable() {

            @Override
            public void run() {
                LOG.info("Invoked Shutdown on DetectingGateway.");
            }
        });
    } catch (ShutdownException e) {
        LOG.error("Exception while shutting down Detecting Gateway", e);
    }
}
Also used : ShutdownException(io.fabric8.common.util.ShutdownTracker.ShutdownException) ObjectName(javax.management.ObjectName)

Example 84 with io.fabric8.kubernetes.api.model

use of io.fabric8.kubernetes.api.model in project fabric8 by jboss-fuse.

the class VersionInfoAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    if (!profileService.hasVersion(versionId)) {
        System.out.println("Version " + versionId + " does not exists!");
        return 1;
    }
    Version version = profileService.getRequiredVersion(versionId);
    String description = version.getAttributes().get(Version.DESCRIPTION);
    String derivedFrom = version.getAttributes().get(Version.PARENT);
    boolean defaultVersion = version.getId().equals(fabricService.getDefaultVersionId());
    List<Profile> profiles = CommandUtils.sortProfiles(version.getProfiles());
    List<Container> containerList = new ArrayList<Container>();
    for (String c : dataStore.getContainers()) {
        Container container = fabricService.getContainer(c);
        if (version.getId().equals(container.getVersion().getId())) {
            containerList.add(container);
        }
    }
    Container[] containers = CommandUtils.sortContainers(containerList.toArray(new io.fabric8.api.Container[containerList.size()]));
    System.out.println(String.format(FORMAT, "Name:", version.getId()));
    System.out.println(String.format(FORMAT, "Description:", (description != null ? description : "")));
    System.out.println(String.format(FORMAT, "Derived From:", (derivedFrom) != null ? derivedFrom : ""));
    System.out.println(String.format(FORMAT, "Default Version:", defaultVersion));
    if (containers.length == 0) {
        System.out.println(String.format(FORMAT, "Containers:", ""));
    } else {
        for (int i = 0; i < containers.length; i++) {
            if (i == 0) {
                System.out.println(String.format(FORMAT, "Containers (" + containers.length + "):", containers[i].getId()));
            } else {
                System.out.println(String.format(FORMAT, "", containers[i].getId()));
            }
        }
    }
    if (profiles.size() == 0) {
        System.out.println(String.format(FORMAT, "Profiles:", ""));
    } else {
        for (int i = 0; i < profiles.size(); i++) {
            if (i == 0) {
                System.out.println(String.format(FORMAT, "Profiles (" + profiles.size() + "):", profiles.get(i).getId()));
            } else {
                System.out.println(String.format(FORMAT, "", profiles.get(i).getId()));
            }
        }
    }
    return null;
}
Also used : Container(io.fabric8.api.Container) Version(io.fabric8.api.Version) ArrayList(java.util.ArrayList) Profile(io.fabric8.api.Profile)

Example 85 with io.fabric8.kubernetes.api.model

use of io.fabric8.kubernetes.api.model in project fabric8 by jboss-fuse.

the class DeploymentAgentTest method testResolveOptionalImports.

@Test
@SuppressWarnings("unchecked")
public void testResolveOptionalImports() throws Exception {
    CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning");
    CommandSupport.executeCommand("fabric:profile-create --parent default test-profile");
    CommandSupport.executeCommand("fabric:profile-edit --pid io.fabric8.agent/resolve.optional.imports=true test-profile");
    CommandSupport.executeCommand("fabric:profile-edit --feature spring-struts test-profile");
    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_b").withProfiles("test-profile").assertProvisioningResult().build(fabricService);
        try {
            String command = "fabric:container-connect -u admin -p admin " + containers.iterator().next().getId() + " osgi:list -t 0 -s | grep org.apache.servicemix.bundles.struts";
            String result = CommandSupport.executeCommand(command);
            assertTrue("Result contains struts, but was: " + result, result.contains("org.apache.servicemix.bundles.struts"));
        } finally {
            ContainerBuilder.stop(fabricService, containers);
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)29 FabricService (io.fabric8.api.FabricService)26 File (java.io.File)22 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)18 InputStream (java.io.InputStream)16 Logger (org.slf4j.Logger)16 ServiceLocator (io.fabric8.api.gravia.ServiceLocator)15 CommandSupport (io.fabric8.itests.support.CommandSupport)15 Deployment (org.jboss.arquillian.container.test.api.Deployment)15 StartLevelAware (org.jboss.arquillian.osgi.StartLevelAware)15 OSGiManifestBuilder (org.jboss.osgi.metadata.OSGiManifestBuilder)15 Asset (org.jboss.shrinkwrap.api.asset.Asset)15 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)15 ServiceTracker (org.osgi.util.tracker.ServiceTracker)15 IOException (java.io.IOException)14 Action (org.apache.felix.gogo.commands.Action)14 AbstractCommand (org.apache.felix.gogo.commands.basic.AbstractCommand)14 MavenResolver (io.fabric8.maven.MavenResolver)11 Container (io.fabric8.api.Container)10 BundleContext (org.osgi.framework.BundleContext)9