use of io.fabric8.support.api.Collector in project fabric8 by jboss-fuse.
the class SupportServiceImpl method collect.
@Override
public File collect() {
String name = String.format("%s-%s", "SUPPORT", DATE_TIME_SUFFIX.format(new Date()));
File result = null;
ZipOutputStream file = null;
try {
result = File.createTempFile(name, ".zip");
LOGGER.info("Collecting information for support in file {}", result.getAbsolutePath());
file = new ZipOutputStream(new FileOutputStream(result));
for (Collector collector : collectors) {
for (Resource resource : collector.collect(resourceFactory)) {
collectFromResource(file, resource);
}
}
} catch (IOException e) {
LOGGER.error("Exception occured while collecting support information - resulting support file may not be usable", e);
} finally {
IOHelpers.close(file);
}
return result;
}
use of io.fabric8.support.api.Collector in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildServiceTest method testFailedBuild.
@Test(expected = Fabric8ServiceException.class)
public void testFailedBuild() throws Exception {
BuildService.BuildServiceConfig config = defaultConfig.build();
WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, false, 50, false, false);
OpenShiftMockServer mockServer = collector.getMockServer();
OpenShiftClient client = mockServer.createOpenShiftClient();
OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
service.build(image);
}
use of io.fabric8.support.api.Collector in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildServiceTest method testSuccessfulSecondBuild.
@Test
public void testSuccessfulSecondBuild() throws Exception {
int nTries = 0;
boolean bTestComplete = false;
do {
try {
nTries++;
BuildService.BuildServiceConfig config = defaultConfig.build();
WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, true, 50, true, true);
OpenShiftMockServer mockServer = collector.getMockServer();
OpenShiftClient client = mockServer.createOpenShiftClient();
OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
service.build(image);
assertTrue(mockServer.getRequestCount() > 8);
collector.assertEventsRecordedInOrder("build-config-check", "patch-build-config", "pushed");
collector.assertEventsNotRecorded("new-build-config");
bTestComplete = true;
} catch (Fabric8ServiceException exception) {
Throwable rootCause = getRootCause(exception);
logger.warn("A problem encountered while running test {}, retrying..", exception.getMessage());
// Let's wait for a while, and then retry again
if (rootCause != null && rootCause instanceof IOException) {
continue;
}
}
} while (nTries < MAX_TIMEOUT_RETRIES && !bTestComplete);
}
use of io.fabric8.support.api.Collector in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildServiceTest method createMockServer.
protected WebServerEventCollector<OpenShiftMockServer> createMockServer(BuildService.BuildServiceConfig config, boolean success, long buildDelay, boolean buildConfigExists, boolean imageStreamExists) {
OpenShiftMockServer mockServer = new OpenShiftMockServer(false);
WebServerEventCollector<OpenShiftMockServer> collector = new WebServerEventCollector<>(mockServer);
BuildConfig bc = new BuildConfigBuilder().withNewMetadata().withName(projectName + config.getS2iBuildNameSuffix()).endMetadata().withNewSpec().endSpec().build();
ImageStream imageStream = new ImageStreamBuilder().withNewMetadata().withName(projectName).endMetadata().withStatus(new ImageStreamStatusBuilder().addNewTagLike(new NamedTagEventListBuilder().addNewItem().withImage("abcdef0123456789").endItem().build()).endTag().build()).build();
KubernetesList builds = new KubernetesListBuilder().withItems(new BuildBuilder().withNewMetadata().withName(projectName).endMetadata().build()).withNewMetadata().withResourceVersion("1").endMetadata().build();
String buildStatus = success ? "Complete" : "Fail";
Build build = new BuildBuilder().withNewMetadata().withResourceVersion("2").endMetadata().withNewStatus().withPhase(buildStatus).endStatus().build();
if (!buildConfigExists) {
mockServer.expect().get().withPath("/oapi/v1/namespaces/test/buildconfigs/" + projectName + config.getS2iBuildNameSuffix()).andReply(collector.record("build-config-check").andReturn(404, "")).once();
mockServer.expect().post().withPath("/oapi/v1/namespaces/test/buildconfigs").andReply(collector.record("new-build-config").andReturn(201, bc)).once();
} else {
mockServer.expect().patch().withPath("/oapi/v1/namespaces/test/buildconfigs/" + projectName + config.getS2iBuildNameSuffix()).andReply(collector.record("patch-build-config").andReturn(200, bc)).once();
}
mockServer.expect().get().withPath("/oapi/v1/namespaces/test/buildconfigs/" + projectName + config.getS2iBuildNameSuffix()).andReply(collector.record("build-config-check").andReturn(200, bc)).always();
if (!imageStreamExists) {
mockServer.expect().get().withPath("/oapi/v1/namespaces/test/imagestreams/" + projectName).andReturn(404, "").once();
}
mockServer.expect().get().withPath("/oapi/v1/namespaces/test/imagestreams/" + projectName).andReturn(200, imageStream).always();
mockServer.expect().post().withPath("/oapi/v1/namespaces/test/imagestreams").andReturn(201, imageStream).once();
mockServer.expect().post().withPath("/oapi/v1/namespaces/test/buildconfigs/" + projectName + config.getS2iBuildNameSuffix() + "/instantiatebinary?commit=").andReply(collector.record("pushed").andReturn(201, imageStream)).once();
mockServer.expect().get().withPath("/oapi/v1/namespaces/test/builds").andReply(collector.record("check-build").andReturn(200, builds)).always();
mockServer.expect().get().withPath("/oapi/v1/namespaces/test/builds?labelSelector=openshift.io/build-config.name%3D" + projectName + config.getS2iBuildNameSuffix()).andReturn(200, builds).always();
mockServer.expect().withPath("/oapi/v1/namespaces/test/builds/" + projectName).andReturn(200, build).always();
mockServer.expect().withPath("/oapi/v1/namespaces/test/builds?fieldSelector=metadata.name%3D" + projectName + "&watch=true").andUpgradeToWebSocket().open().waitFor(buildDelay).andEmit(new WatchEvent(build, "MODIFIED")).done().always();
return collector;
}
use of io.fabric8.support.api.Collector in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildServiceTest method checkTarPackage.
@Test
public void checkTarPackage() throws Exception {
int nTries = 0;
boolean bTestComplete = false;
do {
try {
nTries++;
BuildService.BuildServiceConfig config = defaultConfig.build();
WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, true, 50, true, true);
OpenShiftMockServer mockServer = collector.getMockServer();
OpenShiftClient client = mockServer.createOpenShiftClient();
final OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
ImageConfiguration imageWithEnv = new ImageConfiguration.Builder(image).buildConfig(new BuildImageConfiguration.Builder(image.getBuildConfiguration()).env(Collections.singletonMap("FOO", "BAR")).build()).build();
service.createBuildArchive(imageWithEnv);
final List<ArchiverCustomizer> customizer = new LinkedList<>();
new Verifications() {
{
archiveService.createDockerBuildArchive(withInstanceOf(ImageConfiguration.class), withInstanceOf(MojoParameters.class), withCapture(customizer));
assertTrue(customizer.size() == 1);
}
};
customizer.get(0).customize(tarArchiver);
final List<File> file = new LinkedList<>();
new Verifications() {
{
String path;
tarArchiver.addFile(withCapture(file), path = withCapture());
assertEquals(".s2i/environment", path);
}
};
assertEquals(1, file.size());
List<String> lines;
try (FileReader reader = new FileReader(file.get(0))) {
lines = IOUtils.readLines(reader);
}
assertTrue(lines.contains("FOO=BAR"));
bTestComplete = true;
} catch (Fabric8ServiceException exception) {
Throwable rootCause = getRootCause(exception);
logger.warn("A problem encountered while running test {}, retrying..", exception.getMessage());
// Let's wait for a while, and then retry again
if (rootCause != null && rootCause instanceof IOException) {
continue;
}
}
} while (nTries < MAX_TIMEOUT_RETRIES && !bTestComplete);
}
Aggregations