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);
}
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"));
}
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);
}
}
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;
}
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();
}
}
Aggregations